aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2015-03-13 16:49:20 +0100
committerThomas Citharel <tcit@tcit.fr>2015-03-13 16:49:20 +0100
commitf76dab12c9913e0bf4bafd8f59cccdb6bf395994 (patch)
treeeed9ddd964b650b3f8696359b082c2a8cc5242c8 /inc/poche
parentab87a7fe6934b5fa0f06964c67a27826774126b4 (diff)
downloadwallabag-f76dab12c9913e0bf4bafd8f59cccdb6bf395994.tar.gz
wallabag-f76dab12c9913e0bf4bafd8f59cccdb6bf395994.tar.zst
wallabag-f76dab12c9913e0bf4bafd8f59cccdb6bf395994.zip
fix for #1153, a couple of improvements and fixed bugs
Diffstat (limited to 'inc/poche')
-rwxr-xr-xinc/poche/Database.class.php18
-rwxr-xr-xinc/poche/Poche.class.php8
2 files changed, 20 insertions, 6 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index 4f55a7fe..823f834c 100755
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -411,10 +411,22 @@ class Database {
411 411
412 return $count; 412 return $count;
413 } 413 }
414 public function getRandomId($user_id) { 414 public function getRandomId($user_id, $view) {
415 $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()'; 415 $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()';
416 $sql = "SELECT id FROM entries WHERE user_id=? ORDER BY ". $random . " LIMIT 1"; 416 switch ($view) {
417 $params = array($user_id); 417 case 'archive':
418 $sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1";
419 $params = array($user_id,1);
420 break;
421 case 'fav':
422 $sql = "SELECT id FROM entries WHERE user_id=? AND is_fav=? ORDER BY ". $random . " LIMIT 1";
423 $params = array($user_id,1);
424 break;
425 default:
426 $sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1";
427 $params = array($user_id,0);
428 break;
429 }
418 $query = $this->executeQuery($sql, $params); 430 $query = $this->executeQuery($sql, $params);
419 $id = $query->fetchAll(); 431 $id = $query->fetchAll();
420 432
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 4ec724f9..1a5cbe6c 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -406,8 +406,9 @@ class Poche
406 /* For some unknown reason I can't get displayView() to work here (it redirects to home view afterwards). So here's a dirty fix which redirects directly to URL */ 406 /* For some unknown reason I can't get displayView() to work here (it redirects to home view afterwards). So here's a dirty fix which redirects directly to URL */
407 case 'random': 407 case 'random':
408 Tools::logm('get a random article'); 408 Tools::logm('get a random article');
409 if ($this->store->getRandomId($this->user->getId())) { 409 $view = $_GET['view'];
410 $id_array = $this->store->getRandomId($this->user->getId()); 410 if ($this->store->getRandomId($this->user->getId(),$view)) {
411 $id_array = $this->store->getRandomId($this->user->getId(),$view);
411 $id = $id_array[0]; 412 $id = $id_array[0];
412 Tools::redirect('?view=view&id=' . $id[0]); 413 Tools::redirect('?view=view&id=' . $id[0]);
413 Tools::logm('got the article with id ' . $id[0]); 414 Tools::logm('got the article with id ' . $id[0]);
@@ -522,7 +523,7 @@ class Poche
522 $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' )); 523 $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' ));
523 $tpl_vars['page_links'] = $page_links; 524 $tpl_vars['page_links'] = $page_links;
524 $tpl_vars['nb_results'] = $count; 525 $tpl_vars['nb_results'] = $count;
525 $tpl_vars['searchterm'] = $search; 526 $tpl_vars['search_term'] = $search;
526 } 527 }
527 break; 528 break;
528 case 'view': 529 case 'view':
@@ -578,6 +579,7 @@ class Poche
578 'page_links' => '', 579 'page_links' => '',
579 'nb_results' => '', 580 'nb_results' => '',
580 'listmode' => (isset($_COOKIE['listmode']) ? true : false), 581 'listmode' => (isset($_COOKIE['listmode']) ? true : false),
582 'view' => $view,
581 ); 583 );
582 584
583 //if id is given - we retrieve entries by tag: id is tag id 585 //if id is given - we retrieve entries by tag: id is tag id