aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-02-21 13:44:30 +0100
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-02-21 13:44:30 +0100
commite7345a2c4feaa64c8582844425f388e57f1f933d (patch)
tree5f2b7fa7917186052519193542f126692031d095 /inc/poche
parent3ade95a3d79d356ff4979eeaa6cf1fe3c6da1794 (diff)
parent032e0ca13ab8ebf99b5169f6f733db4184cdde6c (diff)
downloadwallabag-e7345a2c4feaa64c8582844425f388e57f1f933d.tar.gz
wallabag-e7345a2c4feaa64c8582844425f388e57f1f933d.tar.zst
wallabag-e7345a2c4feaa64c8582844425f388e57f1f933d.zip
Merge branch 'dev' of git://github.com/mariroz/wallabag into dev
Diffstat (limited to 'inc/poche')
-rwxr-xr-x[-rw-r--r--]inc/poche/Database.class.php79
-rwxr-xr-xinc/poche/Poche.class.php31
-rw-r--r--inc/poche/Tools.class.php2
3 files changed, 71 insertions, 41 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index a366e866..c998fe14 100644..100755
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -10,8 +10,15 @@
10 10
11class Database { 11class Database {
12 var $handle; 12 var $handle;
13 13 private $order = array(
14 function __construct() 14 'ia' => 'ORDER BY entries.id',
15 'id' => 'ORDER BY entries.id DESC',
16 'ta' => 'ORDER BY lower(entries.title)',
17 'td' => 'ORDER BY lower(entries.title) DESC',
18 'default' => 'ORDER BY entries.id'
19 );
20
21 function __construct()
15 { 22 {
16 switch (STORAGE) { 23 switch (STORAGE) {
17 case 'sqlite': 24 case 'sqlite':
@@ -257,48 +264,62 @@ class Database {
257 $query = $this->executeQuery($sql, $params); 264 $query = $this->executeQuery($sql, $params);
258 } 265 }
259 266
260 public function getEntriesByView($view, $user_id, $limit = '') { 267 public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) {
261 switch ($_SESSION['sort']) 268 switch ($view) {
262 { 269 case 'archive':
263 case 'ia': 270 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
264 $order = 'ORDER BY id'; 271 $params = array($user_id, 1);
265 break;
266 case 'id':
267 $order = 'ORDER BY id DESC';
268 break; 272 break;
269 case 'ta': 273 case 'fav' :
270 $order = 'ORDER BY lower(title)'; 274 $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? ";
275 $params = array($user_id, 1);
271 break; 276 break;
272 case 'td': 277 case 'tag' :
273 $order = 'ORDER BY lower(title) DESC'; 278 $sql = "SELECT entries.* FROM entries
279 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
280 WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
281 $params = array($user_id, $tag_id);
274 break; 282 break;
275 default: 283 default:
276 $order = 'ORDER BY id'; 284 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
285 $params = array($user_id, 0);
277 break; 286 break;
278 } 287 }
279 288
280 switch ($view) 289 $sql .= $this->getEntriesOrder().' ' . $limit;
281 { 290
291 $query = $this->executeQuery($sql, $params);
292 $entries = $query->fetchAll();
293
294 return $entries;
295 }
296
297 public function getEntriesByViewCount($view, $user_id, $tag_id = 0) {
298 switch ($view) {
282 case 'archive': 299 case 'archive':
283 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; 300 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
284 $params = array($user_id, 1); 301 $params = array($user_id, 1);
285 break; 302 break;
286 case 'fav' : 303 case 'fav' :
287 $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? " . $order; 304 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? ";
288 $params = array($user_id, 1); 305 $params = array($user_id, 1);
289 break; 306 break;
307 case 'tag' :
308 $sql = "SELECT count(*) FROM entries
309 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
310 WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
311 $params = array($user_id, $tag_id);
312 break;
290 default: 313 default:
291 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; 314 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
292 $params = array($user_id, 0); 315 $params = array($user_id, 0);
293 break; 316 break;
294 } 317 }
295 318
296 $sql .= ' ' . $limit;
297
298 $query = $this->executeQuery($sql, $params); 319 $query = $this->executeQuery($sql, $params);
299 $entries = $query->fetchAll(); 320 list($count) = $query->fetch();
300 321
301 return $entries; 322 return $count;
302 } 323 }
303 324
304 public function updateContent($id, $content, $user_id) { 325 public function updateContent($id, $content, $user_id) {
@@ -420,4 +441,14 @@ class Database {
420 $query = $this->executeQuery($sql_action, $params_action); 441 $query = $this->executeQuery($sql_action, $params_action);
421 return $query; 442 return $query;
422 } 443 }
444
445 private function getEntriesOrder() {
446 if (isset($_SESSION['sort']) and array_key_exists($_SESSION['sort'], $this->order)) {
447 return $this->order[$_SESSION['sort']];
448 }
449 else {
450 return $this->order['default'];
451 }
452 }
453
423} 454}
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index e7985cf1..33dddf1e 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -595,14 +595,7 @@ class Poche
595 $tpl_vars = array( 595 $tpl_vars = array(
596 'entry_id' => $id, 596 'entry_id' => $id,
597 'tags' => $tags, 597 'tags' => $tags,
598 ); 598 'entry' => $entry,
599 break;
600 case 'tag':
601 $entries = $this->store->retrieveEntriesByTag($id, $this->user->getId());
602 $tag = $this->store->retrieveTag($id, $this->user->getId());
603 $tpl_vars = array(
604 'tag' => $tag,
605 'entries' => $entries,
606 ); 599 );
607 break; 600 break;
608 case 'tags': 601 case 'tags':
@@ -643,22 +636,28 @@ class Poche
643 Tools::logm('error in view call : entry is null'); 636 Tools::logm('error in view call : entry is null');
644 } 637 }
645 break; 638 break;
646 default: # home, favorites and archive views 639 default: # home, favorites, archive and tag views
647 $entries = $this->store->getEntriesByView($view, $this->user->getId());
648 $tpl_vars = array( 640 $tpl_vars = array(
649 'entries' => '', 641 'entries' => '',
650 'page_links' => '', 642 'page_links' => '',
651 'nb_results' => '', 643 'nb_results' => '',
652 ); 644 );
653 645
654 if (count($entries) > 0) { 646 //if id is given - we retrive entries by tag: id is tag id
655 $this->pagination->set_total(count($entries)); 647 if ($id) {
648 $tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId());
649 $tpl_vars['id'] = intval($id);
650 }
651
652 $count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id);
653
654 if ($count > 0) {
655 $this->pagination->set_total($count);
656 $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), 656 $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')),
657 $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&')); 657 $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . (($id)?'&id='.$id:'') . '&' ));
658 $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit()); 658 $tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id);
659 $tpl_vars['entries'] = $datas;
660 $tpl_vars['page_links'] = $page_links; 659 $tpl_vars['page_links'] = $page_links;
661 $tpl_vars['nb_results'] = count($entries); 660 $tpl_vars['nb_results'] = $count;
662 } 661 }
663 Tools::logm('display ' . $view . ' view'); 662 Tools::logm('display ' . $view . ' view');
664 break; 663 break;
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index 515a08aa..4ed28ed1 100644
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -92,7 +92,7 @@ class Tools
92 { 92 {
93 $views = array( 93 $views = array(
94 'install', 'import', 'export', 'config', 'tags', 94 'install', 'import', 'export', 'config', 'tags',
95 'edit-tags', 'view', 'login', 'error', 'tag' 95 'edit-tags', 'view', 'login', 'error'
96 ); 96 );
97 97
98 if (in_array($view, $views)) { 98 if (in_array($view, $views)) {