diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/3rdparty/Session.class.php | 13 | ||||
-rw-r--r-- | inc/3rdparty/libraries/feedwriter/FeedItem.php | 1 | ||||
-rwxr-xr-x | inc/poche/Database.class.php | 76 | ||||
-rwxr-xr-x | inc/poche/Poche.class.php | 199 | ||||
-rwxr-xr-x[-rw-r--r--] | inc/poche/Tools.class.php | 73 |
5 files changed, 236 insertions, 126 deletions
diff --git a/inc/3rdparty/Session.class.php b/inc/3rdparty/Session.class.php index b30a31f3..599b68cd 100644 --- a/inc/3rdparty/Session.class.php +++ b/inc/3rdparty/Session.class.php | |||
@@ -33,7 +33,7 @@ class Session | |||
33 | // his/her session is considered expired (3600 sec. = 1 hour) | 33 | // his/her session is considered expired (3600 sec. = 1 hour) |
34 | public static $inactivityTimeout = 86400; | 34 | public static $inactivityTimeout = 86400; |
35 | // Extra timeout for long sessions (if enabled) (82800 sec. = 23 hours) | 35 | // Extra timeout for long sessions (if enabled) (82800 sec. = 23 hours) |
36 | public static $longSessionTimeout = 31536000; | 36 | public static $longSessionTimeout = 604800; // 604800 = a week |
37 | // If you get disconnected often or if your IP address changes often. | 37 | // If you get disconnected often or if your IP address changes often. |
38 | // Let you disable session cookie hijacking protection | 38 | // Let you disable session cookie hijacking protection |
39 | public static $disableSessionProtection = false; | 39 | public static $disableSessionProtection = false; |
@@ -61,7 +61,7 @@ class Session | |||
61 | if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") { | 61 | if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") { |
62 | $ssl = true; | 62 | $ssl = true; |
63 | } | 63 | } |
64 | session_set_cookie_params($cookie['lifetime'], $cookiedir, $_SERVER['HTTP_HOST'], $ssl); | 64 | session_set_cookie_params(self::$longSessionTimeout, $cookiedir, $_SERVER['HTTP_HOST'], $ssl); |
65 | // Use cookies to store session. | 65 | // Use cookies to store session. |
66 | ini_set('session.use_cookies', 1); | 66 | ini_set('session.use_cookies', 1); |
67 | // Force cookies for session (phpsessionID forbidden in URL) | 67 | // Force cookies for session (phpsessionID forbidden in URL) |
@@ -143,7 +143,14 @@ class Session | |||
143 | */ | 143 | */ |
144 | public static function logout() | 144 | public static function logout() |
145 | { | 145 | { |
146 | unset($_SESSION['uid'],$_SESSION['ip'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass'], $_SESSION['longlastingsession'], $_SESSION['poche_user']); | 146 | // unset($_SESSION['uid'],$_SESSION['ip'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass'], $_SESSION['longlastingsession'], $_SESSION['poche_user']); |
147 | |||
148 | // Destruction du cookie (le code peut paraître complexe mais c'est pour être certain de reprendre les mêmes paramètres) | ||
149 | $args = array_merge(array(session_name(), ''), array_values(session_get_cookie_params())); | ||
150 | $args[2] = time() - 3600; | ||
151 | call_user_func_array('setcookie', $args); | ||
152 | // Suppression physique de la session | ||
153 | session_destroy(); | ||
147 | } | 154 | } |
148 | 155 | ||
149 | /** | 156 | /** |
diff --git a/inc/3rdparty/libraries/feedwriter/FeedItem.php b/inc/3rdparty/libraries/feedwriter/FeedItem.php index 9373deeb..0eae5e08 100644 --- a/inc/3rdparty/libraries/feedwriter/FeedItem.php +++ b/inc/3rdparty/libraries/feedwriter/FeedItem.php | |||
@@ -156,6 +156,7 @@ | |||
156 | if($this->version == RSS2 || $this->version == RSS1) | 156 | if($this->version == RSS2 || $this->version == RSS1) |
157 | { | 157 | { |
158 | $this->setElement('link', $link); | 158 | $this->setElement('link', $link); |
159 | $this->setElement('guid', $link); | ||
159 | } | 160 | } |
160 | else | 161 | else |
161 | { | 162 | { |
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index c998fe14..5b51b507 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php | |||
@@ -230,8 +230,30 @@ class Database { | |||
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 | ||
233 | public function updateContentAndTitle($id, $title, $body, $user_id) { | ||
234 | $sql_action = 'UPDATE entries SET content = ?, title = ? WHERE id=? AND user_id=?'; | ||
235 | $params_action = array($body, $title, $id, $user_id); | ||
236 | $query = $this->executeQuery($sql_action, $params_action); | ||
237 | |||
238 | return $query; | ||
239 | } | ||
240 | |||
241 | public function retrieveUnfetchedEntries($user_id, $limit) { | ||
242 | |||
243 | $sql_limit = "LIMIT 0,".$limit; | ||
244 | if (STORAGE == 'postgres') { | ||
245 | $sql_limit = "LIMIT ".$limit." OFFSET 0"; | ||
246 | } | ||
247 | |||
248 | $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND user_id=? ORDER BY id " . $sql_limit; | ||
249 | $query = $this->executeQuery($sql, array($user_id)); | ||
250 | $entries = $query->fetchAll(); | ||
251 | |||
252 | return $entries; | ||
253 | } | ||
254 | |||
233 | public function retrieveAll($user_id) { | 255 | public function retrieveAll($user_id) { |
234 | $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id"; | 256 | $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? ORDER BY id"; |
235 | $query = $this->executeQuery($sql, array($user_id)); | 257 | $query = $this->executeQuery($sql, array($user_id)); |
236 | $entries = $query->fetchAll(); | 258 | $entries = $query->fetchAll(); |
237 | 259 | ||
@@ -250,7 +272,7 @@ class Database { | |||
250 | 272 | ||
251 | public function retrieveOneByURL($url, $user_id) { | 273 | public function retrieveOneByURL($url, $user_id) { |
252 | $entry = NULL; | 274 | $entry = NULL; |
253 | $sql = "SELECT * FROM entries WHERE url=? AND user_id=?"; | 275 | $sql = "SELECT * FROM entries WHERE content <> '' AND url=? AND user_id=?"; |
254 | $params = array($url, $user_id); | 276 | $params = array($url, $user_id); |
255 | $query = $this->executeQuery($sql, $params); | 277 | $query = $this->executeQuery($sql, $params); |
256 | $entry = $query->fetchAll(); | 278 | $entry = $query->fetchAll(); |
@@ -267,21 +289,22 @@ class Database { | |||
267 | public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) { | 289 | public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) { |
268 | switch ($view) { | 290 | switch ($view) { |
269 | case 'archive': | 291 | case 'archive': |
270 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; | 292 | $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; |
271 | $params = array($user_id, 1); | 293 | $params = array($user_id, 1); |
272 | break; | 294 | break; |
273 | case 'fav' : | 295 | case 'fav' : |
274 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? "; | 296 | $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_fav=? "; |
275 | $params = array($user_id, 1); | 297 | $params = array($user_id, 1); |
276 | break; | 298 | break; |
277 | case 'tag' : | 299 | case 'tag' : |
278 | $sql = "SELECT entries.* FROM entries | 300 | $sql = "SELECT entries.* FROM entries |
279 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id | 301 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id |
280 | WHERE entries.user_id=? AND tags_entries.tag_id = ? "; | 302 | WHERE entries.content <> '' AND |
303 | entries.user_id=? AND tags_entries.tag_id = ? "; | ||
281 | $params = array($user_id, $tag_id); | 304 | $params = array($user_id, $tag_id); |
282 | break; | 305 | break; |
283 | default: | 306 | default: |
284 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; | 307 | $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; |
285 | $params = array($user_id, 0); | 308 | $params = array($user_id, 0); |
286 | break; | 309 | break; |
287 | } | 310 | } |
@@ -294,24 +317,25 @@ class Database { | |||
294 | return $entries; | 317 | return $entries; |
295 | } | 318 | } |
296 | 319 | ||
297 | public function getEntriesByViewCount($view, $user_id, $tag_id = 0) { | 320 | public function getEntriesByViewCount($view, $user_id, $tag_id = 0) { |
298 | switch ($view) { | 321 | switch ($view) { |
299 | case 'archive': | 322 | case 'archive': |
300 | $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; | 323 | $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; |
301 | $params = array($user_id, 1); | 324 | $params = array($user_id, 1); |
302 | break; | 325 | break; |
303 | case 'fav' : | 326 | case 'fav' : |
304 | $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? "; | 327 | $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_fav=? "; |
305 | $params = array($user_id, 1); | 328 | $params = array($user_id, 1); |
306 | break; | 329 | break; |
307 | case 'tag' : | 330 | case 'tag' : |
308 | $sql = "SELECT count(*) FROM entries | 331 | $sql = "SELECT count(*) FROM entries |
309 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id | 332 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id |
310 | WHERE entries.user_id=? AND tags_entries.tag_id = ? "; | 333 | WHERE entries.content <> '' AND |
311 | $params = array($user_id, $tag_id); | 334 | entries.user_id=? AND tags_entries.tag_id = ? "; |
312 | break; | 335 | $params = array($user_id, $tag_id); |
336 | break; | ||
313 | default: | 337 | default: |
314 | $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; | 338 | $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; |
315 | $params = array($user_id, 0); | 339 | $params = array($user_id, 0); |
316 | break; | 340 | break; |
317 | } | 341 | } |
@@ -319,7 +343,7 @@ class Database { | |||
319 | $query = $this->executeQuery($sql, $params); | 343 | $query = $this->executeQuery($sql, $params); |
320 | list($count) = $query->fetch(); | 344 | list($count) = $query->fetch(); |
321 | 345 | ||
322 | return $count; | 346 | return $count; |
323 | } | 347 | } |
324 | 348 | ||
325 | public function updateContent($id, $content, $user_id) { | 349 | public function updateContent($id, $content, $user_id) { |
@@ -365,12 +389,15 @@ class Database { | |||
365 | return $this->getHandle()->lastInsertId($column); | 389 | return $this->getHandle()->lastInsertId($column); |
366 | } | 390 | } |
367 | 391 | ||
368 | public function retrieveAllTags($user_id) { | 392 | public function retrieveAllTags($user_id, $term = null) { |
369 | $sql = "SELECT DISTINCT tags.* FROM tags | 393 | $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags |
370 | LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id | 394 | LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id |
371 | LEFT JOIN entries ON tags_entries.entry_id=entries.id | 395 | LEFT JOIN entries ON tags_entries.entry_id=entries.id |
372 | WHERE entries.user_id=?"; | 396 | WHERE entries.content <> '' AND entries.user_id=? |
373 | $query = $this->executeQuery($sql, array($user_id)); | 397 | ". (($term) ? "AND lower(tags.value) LIKE ?" : '') ." |
398 | GROUP BY tags.id, tags.value | ||
399 | ORDER BY tags.value"; | ||
400 | $query = $this->executeQuery($sql, (($term)? array($user_id, strtolower('%'.$term.'%')) : array($user_id) )); | ||
374 | $tags = $query->fetchAll(); | 401 | $tags = $query->fetchAll(); |
375 | 402 | ||
376 | return $tags; | 403 | return $tags; |
@@ -381,7 +408,7 @@ class Database { | |||
381 | $sql = "SELECT DISTINCT tags.* FROM tags | 408 | $sql = "SELECT DISTINCT tags.* FROM tags |
382 | LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id | 409 | LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id |
383 | LEFT JOIN entries ON tags_entries.entry_id=entries.id | 410 | LEFT JOIN entries ON tags_entries.entry_id=entries.id |
384 | WHERE tags.id=? AND entries.user_id=?"; | 411 | WHERE entries.content <> '' AND tags.id=? AND entries.user_id=?"; |
385 | $params = array(intval($id), $user_id); | 412 | $params = array(intval($id), $user_id); |
386 | $query = $this->executeQuery($sql, $params); | 413 | $query = $this->executeQuery($sql, $params); |
387 | $tag = $query->fetchAll(); | 414 | $tag = $query->fetchAll(); |
@@ -393,7 +420,8 @@ class Database { | |||
393 | $sql = | 420 | $sql = |
394 | "SELECT entries.* FROM entries | 421 | "SELECT entries.* FROM entries |
395 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id | 422 | LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id |
396 | WHERE tags_entries.tag_id = ? AND entries.user_id=?"; | 423 | WHERE entries.content <> '' AND |
424 | tags_entries.tag_id = ? AND entries.user_id=?"; | ||
397 | $query = $this->executeQuery($sql, array($tag_id, $user_id)); | 425 | $query = $this->executeQuery($sql, array($tag_id, $user_id)); |
398 | $entries = $query->fetchAll(); | 426 | $entries = $query->fetchAll(); |
399 | 427 | ||
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 87c00b78..7bf33308 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -35,6 +35,7 @@ class Poche | |||
35 | 'ru_RU.utf8' => 'Pусский', | 35 | 'ru_RU.utf8' => 'Pусский', |
36 | 'sl_SI.utf8' => 'Slovenščina', | 36 | 'sl_SI.utf8' => 'Slovenščina', |
37 | 'uk_UA.utf8' => 'Українська', | 37 | 'uk_UA.utf8' => 'Українська', |
38 | 'pt_BR.utf8' => 'Brasileiro', | ||
38 | ); | 39 | ); |
39 | public function __construct() | 40 | public function __construct() |
40 | { | 41 | { |
@@ -361,60 +362,6 @@ class Poche | |||
361 | ); | 362 | ); |
362 | } | 363 | } |
363 | 364 | ||
364 | protected function getPageContent(Url $url) | ||
365 | { | ||
366 | // Saving and clearing context | ||
367 | $REAL = array(); | ||
368 | foreach( $GLOBALS as $key => $value ) { | ||
369 | if( $key != "GLOBALS" && $key != "_SESSION" ) { | ||
370 | $GLOBALS[$key] = array(); | ||
371 | $REAL[$key] = $value; | ||
372 | } | ||
373 | } | ||
374 | // Saving and clearing session | ||
375 | $REAL_SESSION = array(); | ||
376 | foreach( $_SESSION as $key => $value ) { | ||
377 | $REAL_SESSION[$key] = $value; | ||
378 | unset($_SESSION[$key]); | ||
379 | } | ||
380 | |||
381 | // Running code in different context | ||
382 | $scope = function() { | ||
383 | extract( func_get_arg(1) ); | ||
384 | $_GET = $_REQUEST = array( | ||
385 | "url" => $url->getUrl(), | ||
386 | "max" => 5, | ||
387 | "links" => "preserve", | ||
388 | "exc" => "", | ||
389 | "format" => "json", | ||
390 | "submit" => "Create Feed" | ||
391 | ); | ||
392 | ob_start(); | ||
393 | require func_get_arg(0); | ||
394 | $json = ob_get_flush(); | ||
395 | return $json; | ||
396 | }; | ||
397 | $json = $scope( "inc/3rdparty/makefulltextfeed.php", array("url" => $url) ); | ||
398 | |||
399 | // Clearing and restoring context | ||
400 | foreach( $GLOBALS as $key => $value ) { | ||
401 | if( $key != "GLOBALS" && $key != "_SESSION" ) { | ||
402 | unset($GLOBALS[$key]); | ||
403 | } | ||
404 | } | ||
405 | foreach( $REAL as $key => $value ) { | ||
406 | $GLOBALS[$key] = $value; | ||
407 | } | ||
408 | // Clearing and restoring session | ||
409 | foreach( $_SESSION as $key => $value ) { | ||
410 | unset($_SESSION[$key]); | ||
411 | } | ||
412 | foreach( $REAL_SESSION as $key => $value ) { | ||
413 | $_SESSION[$key] = $value; | ||
414 | } | ||
415 | return json_decode($json, true); | ||
416 | } | ||
417 | |||
418 | /** | 365 | /** |
419 | * Call action (mark as fav, archive, delete, etc.) | 366 | * Call action (mark as fav, archive, delete, etc.) |
420 | */ | 367 | */ |
@@ -423,17 +370,25 @@ class Poche | |||
423 | switch ($action) | 370 | switch ($action) |
424 | { | 371 | { |
425 | case 'add': | 372 | case 'add': |
426 | $content = $this->getPageContent($url); | 373 | if (!$import) { |
427 | $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); | 374 | $content = Tools::getPageContent($url); |
428 | $body = $content['rss']['channel']['item']['description']; | 375 | $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); |
429 | 376 | $body = $content['rss']['channel']['item']['description']; | |
430 | // clean content from prevent xss attack | 377 | |
431 | $config = HTMLPurifier_Config::createDefault(); | 378 | // clean content from prevent xss attack |
432 | $purifier = new HTMLPurifier($config); | 379 | $config = HTMLPurifier_Config::createDefault(); |
433 | $title = $purifier->purify($title); | 380 | $config->set('Cache.SerializerPath', CACHE); |
434 | $body = $purifier->purify($body); | 381 | $purifier = new HTMLPurifier($config); |
382 | $title = $purifier->purify($title); | ||
383 | $body = $purifier->purify($body); | ||
384 | } | ||
385 | else { | ||
386 | $title = ''; | ||
387 | $body = ''; | ||
388 | } | ||
435 | 389 | ||
436 | //search for possible duplicate if not in import mode | 390 | //search for possible duplicate if not in import mode |
391 | $duplicate = NULL; | ||
437 | if (!$import) { | 392 | if (!$import) { |
438 | $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); | 393 | $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); |
439 | } | 394 | } |
@@ -534,25 +489,33 @@ class Poche | |||
534 | Tools::logm('error : article not found'); | 489 | Tools::logm('error : article not found'); |
535 | Tools::redirect(); | 490 | Tools::redirect(); |
536 | } | 491 | } |
492 | //get all already set tags to preven duplicates | ||
493 | $already_set_tags = array(); | ||
494 | $entry_tags = $this->store->retrieveTagsByEntry($entry_id); | ||
495 | foreach ($entry_tags as $tag) { | ||
496 | $already_set_tags[] = $tag['value']; | ||
497 | } | ||
537 | foreach($tags as $key => $tag_value) { | 498 | foreach($tags as $key => $tag_value) { |
538 | $value = trim($tag_value); | 499 | $value = trim($tag_value); |
539 | $tag = $this->store->retrieveTagByValue($value); | 500 | if ($value && !in_array($value, $already_set_tags)) { |
540 | 501 | $tag = $this->store->retrieveTagByValue($value); | |
541 | if (is_null($tag)) { | 502 | |
542 | # we create the tag | 503 | if (is_null($tag)) { |
543 | $tag = $this->store->createTag($value); | 504 | # we create the tag |
544 | $sequence = ''; | 505 | $tag = $this->store->createTag($value); |
545 | if (STORAGE == 'postgres') { | 506 | $sequence = ''; |
546 | $sequence = 'tags_id_seq'; | 507 | if (STORAGE == 'postgres') { |
547 | } | 508 | $sequence = 'tags_id_seq'; |
548 | $tag_id = $this->store->getLastId($sequence); | 509 | } |
549 | } | 510 | $tag_id = $this->store->getLastId($sequence); |
550 | else { | 511 | } |
551 | $tag_id = $tag['id']; | 512 | else { |
513 | $tag_id = $tag['id']; | ||
514 | } | ||
515 | |||
516 | # we assign the tag to the article | ||
517 | $this->store->setTagToEntry($tag_id, $entry_id); | ||
552 | } | 518 | } |
553 | |||
554 | # we assign the tag to the article | ||
555 | $this->store->setTagToEntry($tag_id, $entry_id); | ||
556 | } | 519 | } |
557 | if(!$import) { | 520 | if(!$import) { |
558 | Tools::redirect(); | 521 | Tools::redirect(); |
@@ -581,8 +544,12 @@ class Poche | |||
581 | switch ($view) | 544 | switch ($view) |
582 | { | 545 | { |
583 | case 'config': | 546 | case 'config': |
584 | $dev = trim($this->getPocheVersion('dev')); | 547 | $dev_infos = $this->getPocheVersion('dev'); |
585 | $prod = trim($this->getPocheVersion('prod')); | 548 | $dev = trim($dev_infos[0]); |
549 | $check_time_dev = date('d-M-Y H:i', $dev_infos[1]); | ||
550 | $prod_infos = $this->getPocheVersion('prod'); | ||
551 | $prod = trim($prod_infos[0]); | ||
552 | $check_time_prod = date('d-M-Y H:i', $prod_infos[1]); | ||
586 | $compare_dev = version_compare(POCHE, $dev); | 553 | $compare_dev = version_compare(POCHE, $dev); |
587 | $compare_prod = version_compare(POCHE, $prod); | 554 | $compare_prod = version_compare(POCHE, $prod); |
588 | $themes = $this->getInstalledThemes(); | 555 | $themes = $this->getInstalledThemes(); |
@@ -594,6 +561,8 @@ class Poche | |||
594 | 'languages' => $languages, | 561 | 'languages' => $languages, |
595 | 'dev' => $dev, | 562 | 'dev' => $dev, |
596 | 'prod' => $prod, | 563 | 'prod' => $prod, |
564 | 'check_time_dev' => $check_time_dev, | ||
565 | 'check_time_prod' => $check_time_prod, | ||
597 | 'compare_dev' => $compare_dev, | 566 | 'compare_dev' => $compare_dev, |
598 | 'compare_prod' => $compare_prod, | 567 | 'compare_prod' => $compare_prod, |
599 | 'token' => $token, | 568 | 'token' => $token, |
@@ -619,7 +588,17 @@ class Poche | |||
619 | break; | 588 | break; |
620 | case 'tags': | 589 | case 'tags': |
621 | $token = $this->user->getConfigValue('token'); | 590 | $token = $this->user->getConfigValue('token'); |
622 | $tags = $this->store->retrieveAllTags($this->user->getId()); | 591 | //if term is set - search tags for this term |
592 | $term = Tools::checkVar('term'); | ||
593 | $tags = $this->store->retrieveAllTags($this->user->getId(), $term); | ||
594 | if (Tools::isAjaxRequest()) { | ||
595 | $result = array(); | ||
596 | foreach ($tags as $tag) { | ||
597 | $result[] = $tag['value']; | ||
598 | } | ||
599 | echo json_encode($result); | ||
600 | exit; | ||
601 | } | ||
623 | $tpl_vars = array( | 602 | $tpl_vars = array( |
624 | 'token' => $token, | 603 | 'token' => $token, |
625 | 'user_id' => $this->user->getId(), | 604 | 'user_id' => $this->user->getId(), |
@@ -660,6 +639,7 @@ class Poche | |||
660 | 'entries' => '', | 639 | 'entries' => '', |
661 | 'page_links' => '', | 640 | 'page_links' => '', |
662 | 'nb_results' => '', | 641 | 'nb_results' => '', |
642 | 'listmode' => (isset($_COOKIE['listmode']) ? true : false), | ||
663 | ); | 643 | ); |
664 | 644 | ||
665 | //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 |
@@ -895,7 +875,9 @@ class Poche | |||
895 | # the second <ol> is for read links | 875 | # the second <ol> is for read links |
896 | $read = 1; | 876 | $read = 1; |
897 | } | 877 | } |
898 | $this->messages->add('s', _('import from instapaper completed')); | 878 | |
879 | $unlink = unlink($targetFile); | ||
880 | $this->messages->add('s', _('import from instapaper completed. You have to execute the cron to fetch content.')); | ||
899 | Tools::logm('import from instapaper completed'); | 881 | Tools::logm('import from instapaper completed'); |
900 | Tools::redirect(); | 882 | Tools::redirect(); |
901 | } | 883 | } |
@@ -939,7 +921,9 @@ class Poche | |||
939 | # the second <ul> is for read links | 921 | # the second <ul> is for read links |
940 | $read = 1; | 922 | $read = 1; |
941 | } | 923 | } |
942 | $this->messages->add('s', _('import from pocket completed')); | 924 | |
925 | $unlink = unlink($targetFile); | ||
926 | $this->messages->add('s', _('import from pocket completed. You have to execute the cron to fetch content.')); | ||
943 | Tools::logm('import from pocket completed'); | 927 | Tools::logm('import from pocket completed'); |
944 | Tools::redirect(); | 928 | Tools::redirect(); |
945 | } | 929 | } |
@@ -995,7 +979,9 @@ class Poche | |||
995 | } | 979 | } |
996 | } | 980 | } |
997 | } | 981 | } |
998 | $this->messages->add('s', _('import from Readability completed. ' . $count . ' new links.')); | 982 | |
983 | unlink($targetFile); | ||
984 | $this->messages->add('s', _('import from Readability completed. You have to execute the cron to fetch content.')); | ||
999 | Tools::logm('import from Readability completed'); | 985 | Tools::logm('import from Readability completed'); |
1000 | Tools::redirect(); | 986 | Tools::redirect(); |
1001 | } | 987 | } |
@@ -1041,7 +1027,9 @@ class Poche | |||
1041 | } | 1027 | } |
1042 | 1028 | ||
1043 | } | 1029 | } |
1044 | $this->messages->add('s', _('import from Poche completed. ' . $count . ' new links.')); | 1030 | |
1031 | unlink($targetFile); | ||
1032 | $this->messages->add('s', _('import from Poche completed. You have to execute the cron to fetch content.')); | ||
1045 | Tools::logm('import from Poche completed'); | 1033 | Tools::logm('import from Poche completed'); |
1046 | Tools::redirect(); | 1034 | Tools::redirect(); |
1047 | } | 1035 | } |
@@ -1066,13 +1054,7 @@ class Poche | |||
1066 | Tools::redirect(); | 1054 | Tools::redirect(); |
1067 | } | 1055 | } |
1068 | 1056 | ||
1069 | $targetDefinition = 'IMPORT_' . strtoupper($from) . '_FILE'; | 1057 | $targetFile = CACHE . '/' . constant(strtoupper($from) . '_FILE'); |
1070 | $targetFile = constant($targetDefinition); | ||
1071 | |||
1072 | if (! defined($targetDefinition)) { | ||
1073 | $this->messages->add('e', _('Incomplete inc/poche/define.inc.php file, please define "' . $targetDefinition . '".')); | ||
1074 | Tools::redirect(); | ||
1075 | } | ||
1076 | 1058 | ||
1077 | if (! file_exists($targetFile)) { | 1059 | if (! file_exists($targetFile)) { |
1078 | $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.')); | 1060 | $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.')); |
@@ -1082,6 +1064,22 @@ class Poche | |||
1082 | $this->$providers[$from]($targetFile); | 1064 | $this->$providers[$from]($targetFile); |
1083 | } | 1065 | } |
1084 | 1066 | ||
1067 | public function uploadFile() { | ||
1068 | if(isset($_FILES['file'])) | ||
1069 | { | ||
1070 | $dir = CACHE . '/'; | ||
1071 | $file = basename($_FILES['file']['name']); | ||
1072 | if(move_uploaded_file($_FILES['file']['tmp_name'], $dir . $file)) { | ||
1073 | $this->messages->add('s', _('File uploaded. You can now execute import.')); | ||
1074 | } | ||
1075 | else { | ||
1076 | $this->messages->add('e', _('Error while importing file. Do you have access to upload it?')); | ||
1077 | } | ||
1078 | } | ||
1079 | |||
1080 | Tools::redirect('?view=config'); | ||
1081 | } | ||
1082 | |||
1085 | /** | 1083 | /** |
1086 | * export poche entries in json | 1084 | * export poche entries in json |
1087 | * @return json all poche entries | 1085 | * @return json all poche entries |
@@ -1103,15 +1101,17 @@ class Poche | |||
1103 | private function getPocheVersion($which = 'prod') | 1101 | private function getPocheVersion($which = 'prod') |
1104 | { | 1102 | { |
1105 | $cache_file = CACHE . '/' . $which; | 1103 | $cache_file = CACHE . '/' . $which; |
1104 | $check_time = time(); | ||
1106 | 1105 | ||
1107 | # checks if the cached version file exists | 1106 | # checks if the cached version file exists |
1108 | if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) { | 1107 | if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) { |
1109 | $version = file_get_contents($cache_file); | 1108 | $version = file_get_contents($cache_file); |
1109 | $check_time = filemtime($cache_file); | ||
1110 | } else { | 1110 | } else { |
1111 | $version = file_get_contents('http://static.wallabag.org/versions/' . $which); | 1111 | $version = file_get_contents('http://static.wallabag.org/versions/' . $which); |
1112 | file_put_contents($cache_file, $version, LOCK_EX); | 1112 | file_put_contents($cache_file, $version, LOCK_EX); |
1113 | } | 1113 | } |
1114 | return $version; | 1114 | return array($version, $check_time); |
1115 | } | 1115 | } |
1116 | 1116 | ||
1117 | public function generateToken() | 1117 | public function generateToken() |
@@ -1136,6 +1136,10 @@ class Poche | |||
1136 | $allowed_types = array('home', 'fav', 'archive', 'tag'); | 1136 | $allowed_types = array('home', 'fav', 'archive', 'tag'); |
1137 | $config = $this->store->getConfigUser($user_id); | 1137 | $config = $this->store->getConfigUser($user_id); |
1138 | 1138 | ||
1139 | if ($config == null) { | ||
1140 | die(_('User with this id (' . $user_id . ') does not exist.')); | ||
1141 | } | ||
1142 | |||
1139 | if (!in_array($type, $allowed_types) || | 1143 | if (!in_array($type, $allowed_types) || |
1140 | $token != $config['token']) { | 1144 | $token != $config['token']) { |
1141 | die(_('Uh, there is a problem while generating feeds.')); | 1145 | die(_('Uh, there is a problem while generating feeds.')); |
@@ -1145,8 +1149,9 @@ class Poche | |||
1145 | $feed = new FeedWriter(RSS2); | 1149 | $feed = new FeedWriter(RSS2); |
1146 | $feed->setTitle('wallabag — ' . $type . ' feed'); | 1150 | $feed->setTitle('wallabag — ' . $type . ' feed'); |
1147 | $feed->setLink(Tools::getPocheUrl()); | 1151 | $feed->setLink(Tools::getPocheUrl()); |
1148 | $feed->setChannelElement('updated', date(DATE_RSS , time())); | 1152 | $feed->setChannelElement('pubDate', date(DATE_RSS , time())); |
1149 | $feed->setChannelElement('author', 'wallabag'); | 1153 | $feed->setChannelElement('generator', 'wallabag'); |
1154 | $feed->setDescription('wallabag ' . $type . ' elements'); | ||
1150 | 1155 | ||
1151 | if ($type == 'tag') { | 1156 | if ($type == 'tag') { |
1152 | $entries = $this->store->retrieveEntriesByTag($tag_id, $user_id); | 1157 | $entries = $this->store->retrieveEntriesByTag($tag_id, $user_id); |
@@ -1159,7 +1164,7 @@ class Poche | |||
1159 | foreach ($entries as $entry) { | 1164 | foreach ($entries as $entry) { |
1160 | $newItem = $feed->createNewItem(); | 1165 | $newItem = $feed->createNewItem(); |
1161 | $newItem->setTitle($entry['title']); | 1166 | $newItem->setTitle($entry['title']); |
1162 | $newItem->setLink(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); | 1167 | $newItem->setLink($entry['url']); |
1163 | $newItem->setDate(time()); | 1168 | $newItem->setDate(time()); |
1164 | $newItem->setDescription($entry['content']); | 1169 | $newItem->setDescription($entry['content']); |
1165 | $feed->addItem($newItem); | 1170 | $feed->addItem($newItem); |
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 4ed28ed1..ad451fc6 100644..100755 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php | |||
@@ -193,7 +193,7 @@ class Tools | |||
193 | 193 | ||
194 | public static function logm($message) | 194 | public static function logm($message) |
195 | { | 195 | { |
196 | if (DEBUG_POCHE) { | 196 | if (DEBUG_POCHE && php_sapi_name() != 'cli') { |
197 | $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; | 197 | $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; |
198 | file_put_contents(CACHE . '/log.txt', $t, FILE_APPEND); | 198 | file_put_contents(CACHE . '/log.txt', $t, FILE_APPEND); |
199 | error_log('DEBUG POCHE : ' . $message); | 199 | error_log('DEBUG POCHE : ' . $message); |
@@ -241,7 +241,6 @@ class Tools | |||
241 | } | 241 | } |
242 | } | 242 | } |
243 | 243 | ||
244 | |||
245 | public static function download_db() { | 244 | public static function download_db() { |
246 | header('Content-Disposition: attachment; filename="poche.sqlite.gz"'); | 245 | header('Content-Disposition: attachment; filename="poche.sqlite.gz"'); |
247 | self::status(200); | 246 | self::status(200); |
@@ -252,4 +251,74 @@ class Tools | |||
252 | 251 | ||
253 | exit; | 252 | exit; |
254 | } | 253 | } |
254 | |||
255 | public static function getPageContent(Url $url) | ||
256 | { | ||
257 | // Saving and clearing context | ||
258 | $REAL = array(); | ||
259 | foreach( $GLOBALS as $key => $value ) { | ||
260 | if( $key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS' ) { | ||
261 | $GLOBALS[$key] = array(); | ||
262 | $REAL[$key] = $value; | ||
263 | } | ||
264 | } | ||
265 | // Saving and clearing session | ||
266 | if ( isset($_SESSION) ) { | ||
267 | $REAL_SESSION = array(); | ||
268 | foreach( $_SESSION as $key => $value ) { | ||
269 | $REAL_SESSION[$key] = $value; | ||
270 | unset($_SESSION[$key]); | ||
271 | } | ||
272 | } | ||
273 | |||
274 | // Running code in different context | ||
275 | $scope = function() { | ||
276 | extract( func_get_arg(1) ); | ||
277 | $_GET = $_REQUEST = array( | ||
278 | "url" => $url->getUrl(), | ||
279 | "max" => 5, | ||
280 | "links" => "preserve", | ||
281 | "exc" => "", | ||
282 | "format" => "json", | ||
283 | "submit" => "Create Feed" | ||
284 | ); | ||
285 | ob_start(); | ||
286 | require func_get_arg(0); | ||
287 | $json = ob_get_contents(); | ||
288 | ob_end_clean(); | ||
289 | return $json; | ||
290 | }; | ||
291 | $json = $scope( "inc/3rdparty/makefulltextfeed.php", array("url" => $url) ); | ||
292 | |||
293 | // Clearing and restoring context | ||
294 | foreach( $GLOBALS as $key => $value ) { | ||
295 | if( $key != "GLOBALS" && $key != "_SESSION" ) { | ||
296 | unset($GLOBALS[$key]); | ||
297 | } | ||
298 | } | ||
299 | foreach( $REAL as $key => $value ) { | ||
300 | $GLOBALS[$key] = $value; | ||
301 | } | ||
302 | // Clearing and restoring session | ||
303 | if ( isset($REAL_SESSION) ) { | ||
304 | foreach( $_SESSION as $key => $value ) { | ||
305 | unset($_SESSION[$key]); | ||
306 | } | ||
307 | foreach( $REAL_SESSION as $key => $value ) { | ||
308 | $_SESSION[$key] = $value; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | return json_decode($json, true); | ||
313 | } | ||
314 | |||
315 | /** | ||
316 | * Returns whether we handle an AJAX (XMLHttpRequest) request. | ||
317 | * @return boolean whether we handle an AJAX (XMLHttpRequest) request. | ||
318 | */ | ||
319 | public static function isAjaxRequest() | ||
320 | { | ||
321 | return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest'; | ||
322 | } | ||
323 | |||
255 | } | 324 | } |