diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 4f55a7fe2..823f834c8 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -411,10 +411,22 @@ class Database { return $count; } - public function getRandomId($user_id) { + public function getRandomId($user_id, $view) { $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()'; - $sql = "SELECT id FROM entries WHERE user_id=? ORDER BY ". $random . " LIMIT 1"; - $params = array($user_id); + switch ($view) { + case 'archive': + $sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1"; + $params = array($user_id,1); + break; + case 'fav': + $sql = "SELECT id FROM entries WHERE user_id=? AND is_fav=? ORDER BY ". $random . " LIMIT 1"; + $params = array($user_id,1); + break; + default: + $sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1"; + $params = array($user_id,0); + break; + } $query = $this->executeQuery($sql, $params); $id = $query->fetchAll(); diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 4ec724f9f..1a5cbe6cc 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -406,8 +406,9 @@ class Poche /* 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 */ case 'random': Tools::logm('get a random article'); - if ($this->store->getRandomId($this->user->getId())) { - $id_array = $this->store->getRandomId($this->user->getId()); + $view = $_GET['view']; + if ($this->store->getRandomId($this->user->getId(),$view)) { + $id_array = $this->store->getRandomId($this->user->getId(),$view); $id = $id_array[0]; Tools::redirect('?view=view&id=' . $id[0]); Tools::logm('got the article with id ' . $id[0]); @@ -522,7 +523,7 @@ class Poche $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' )); $tpl_vars['page_links'] = $page_links; $tpl_vars['nb_results'] = $count; - $tpl_vars['searchterm'] = $search; + $tpl_vars['search_term'] = $search; } break; case 'view': @@ -578,6 +579,7 @@ class Poche 'page_links' => '', 'nb_results' => '', 'listmode' => (isset($_COOKIE['listmode']) ? true : false), + 'view' => $view, ); //if id is given - we retrieve entries by tag: id is tag id diff --git a/themes/baggy/home.twig b/themes/baggy/home.twig index 93d2815b3..5f097f3f7 100755 --- a/themes/baggy/home.twig +++ b/themes/baggy/home.twig @@ -15,8 +15,15 @@ {% if tag %}