]> git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/poche/Database.class.php
fixed a postgresql-related bug, more database functions secured and add an exception...
[github/wallabag/wallabag.git] / inc / poche / Database.class.php
1 <?php
2 /**
3 * wallabag, self hostable application allowing you to not miss any content anymore
4 *
5 * @category wallabag
6 * @author Nicolas LÅ“uillet <nicolas@loeuillet.org>
7 * @copyright 2013
8 * @license http://opensource.org/licenses/MIT see COPYING file
9 */
10
11 class Database {
12
13 var $handle;
14 private $order = array (
15 'ia' => 'ORDER BY entries.id',
16 'id' => 'ORDER BY entries.id DESC',
17 'ta' => 'ORDER BY lower(entries.title)',
18 'td' => 'ORDER BY lower(entries.title) DESC',
19 'default' => 'ORDER BY entries.id'
20 );
21
22 function __construct()
23 {
24 switch (STORAGE) {
25 case 'sqlite':
26 // Check if /db is writeable
27 if ( !is_writable(STORAGE_SQLITE) || !is_writable(dirname(STORAGE_SQLITE))) {
28 die('An error occured: "db" directory must be writeable for your web server user!');
29 }
30 $db_path = 'sqlite:' . STORAGE_SQLITE;
31 $this->handle = new PDO($db_path);
32 break;
33 case 'mysql':
34 if (MYSQL_USE_UTF8MB4) {
35 $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4';
36 $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array(
37 PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
38 ));
39 } else {
40 $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB;
41 $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD);
42 }
43 break;
44 case 'postgres':
45 $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB;
46 $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD);
47 break;
48 default:
49 die(STORAGE . ' is not a recognised database system !');
50 }
51
52 $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
53 $this->_checkTags();
54 Tools::logm('storage type ' . STORAGE);
55 }
56
57 private function getHandle()
58 {
59 return $this->handle;
60 }
61
62 private function _checkTags()
63 {
64
65 if (STORAGE == 'sqlite') {
66 $sql = '
67 CREATE TABLE IF NOT EXISTS tags (
68 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
69 value TEXT
70 )';
71 }
72 elseif(STORAGE == 'mysql') {
73 $sql = '
74 CREATE TABLE IF NOT EXISTS `tags` (
75 `id` int(11) NOT NULL AUTO_INCREMENT,
76 `value` varchar(255) NOT NULL,
77 PRIMARY KEY (`id`)
78 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
79 ';
80 }
81 else {
82 $sql = '
83 CREATE TABLE IF NOT EXISTS tags (
84 id bigserial primary key,
85 value varchar(255) NOT NULL
86 );
87 ';
88 }
89
90 $query = $this->executeQuery($sql, array());
91
92 if (STORAGE == 'sqlite') {
93 $sql = '
94 CREATE TABLE IF NOT EXISTS tags_entries (
95 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
96 entry_id INTEGER,
97 tag_id INTEGER,
98 FOREIGN KEY(entry_id) REFERENCES entries(id) ON DELETE CASCADE,
99 FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE
100 )';
101 }
102 elseif(STORAGE == 'mysql') {
103 $sql = '
104 CREATE TABLE IF NOT EXISTS `tags_entries` (
105 `id` int(11) NOT NULL AUTO_INCREMENT,
106 `entry_id` int(11) NOT NULL,
107 `tag_id` int(11) NOT NULL,
108 FOREIGN KEY(entry_id) REFERENCES entries(id) ON DELETE CASCADE,
109 FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE,
110 PRIMARY KEY (`id`)
111 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
112 ';
113 }
114 else {
115 $sql = '
116 CREATE TABLE IF NOT EXISTS tags_entries (
117 id bigserial primary key,
118 entry_id integer NOT NULL,
119 tag_id integer NOT NULL
120 )
121 ';
122 }
123
124 $query = $this->executeQuery($sql, array());
125 }
126
127 public function install($login, $password, $email = '')
128 {
129 $sql = 'INSERT INTO users ( username, password, name, email) VALUES (?, ?, ?, ?)';
130 $params = array($login, $password, $login, $email);
131 $query = $this->executeQuery($sql, $params);
132
133 $sequence = '';
134 if (STORAGE == 'postgres') {
135 $sequence = 'users_id_seq';
136 }
137
138 $id_user = intval($this->getLastId($sequence));
139
140 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
141 $params = array($id_user, 'pager', PAGINATION);
142 $query = $this->executeQuery($sql, $params);
143
144 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
145 $params = array($id_user, 'language', LANG);
146 $query = $this->executeQuery($sql, $params);
147
148 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
149 $params = array($id_user, 'theme', DEFAULT_THEME);
150 $query = $this->executeQuery($sql, $params);
151
152 return TRUE;
153 }
154
155 public function getConfigUser($id)
156 {
157 $sql = "SELECT * FROM users_config WHERE user_id = ?";
158 $query = $this->executeQuery($sql, array($id));
159 $result = ($query) ? $query->fetchAll() : false;
160 $user_config = false;
161 if ($query) {
162 $user_config = array();
163
164 foreach ($result as $key => $value) {
165 $user_config[$value['name']] = $value['value'];
166 }
167 }
168
169 return $user_config;
170 }
171
172 public function userExists($username)
173 {
174 $sql = "SELECT * FROM users WHERE username=?";
175 $query = $this->executeQuery($sql, array($username));
176 $login = $query->fetchAll();
177 return (isset($login[0]) && $query) ? true : false;
178 }
179
180 public function login($username, $password, $isauthenticated = FALSE)
181 {
182 if ($isauthenticated) {
183 $sql = "SELECT * FROM users WHERE username=?";
184 $query = $this->executeQuery($sql, array($username));
185 } else {
186 $sql = "SELECT * FROM users WHERE username=? AND password=?";
187 $query = $this->executeQuery($sql, array($username, $password));
188 }
189 $login = ($query) ? $query->fetchAll() : false;
190
191 $user = array();
192 if ($login[0]) {
193 $user['id'] = $login[0]['id'];
194 $user['username'] = $login[0]['username'];
195 $user['password'] = $login[0]['password'];
196 $user['name'] = $login[0]['name'];
197 $user['email'] = $login[0]['email'];
198 $user['config'] = $this->getConfigUser($login[0]['id']);
199 }
200
201 return $user;
202 }
203
204 public function updatePassword($userId, $password)
205 {
206 $sql_update = "UPDATE users SET password=? WHERE id=?";
207 $params_update = array($password, $userId);
208 $query = $this->executeQuery($sql_update, $params_update);
209 }
210
211 public function updateUserConfig($userId, $key, $value)
212 {
213 $config = $this->getConfigUser($userId);
214
215 if (! isset($config[$key])) {
216 $sql = "INSERT INTO users_config (value, user_id, name) VALUES (?, ?, ?)";
217 }
218 else {
219 $sql = "UPDATE users_config SET value=? WHERE user_id=? AND name=?";
220 }
221
222 $params = array($value, $userId, $key);
223 $query = $this->executeQuery($sql, $params);
224 }
225
226 private function executeQuery($sql, $params)
227 {
228 try
229 {
230 $query = $this->getHandle()->prepare($sql);
231 $query->execute($params);
232 return $query;
233 }
234 catch (Exception $e)
235 {
236 Tools::logm('execute query error : '.$e->getMessage());
237 return FALSE;
238 }
239 }
240
241 public function listUsers($username = NULL)
242 {
243 $sql = 'SELECT count(*) FROM users'.( $username ? ' WHERE username=?' : '');
244 $query = $this->executeQuery($sql, ( $username ? array($username) : array()));
245 list($count) = ($query) ? $query->fetch() : false;
246 return $count;
247 }
248
249 public function getUserPassword($userID)
250 {
251 $sql = "SELECT * FROM users WHERE id=?";
252 $query = $this->executeQuery($sql, array($userID));
253 $password = $query->fetchAll();
254 return ($query) ? $password[0]['password'] : false;
255 }
256
257 public function deleteUserConfig($userID)
258 {
259 $sql_action = 'DELETE from users_config WHERE user_id=?';
260 $params_action = array($userID);
261 $query = $this->executeQuery($sql_action, $params_action);
262 return ($query) ? $query : false;
263 }
264
265 public function deleteTagsEntriesAndEntries($userID)
266 {
267 $entries = $this->retrieveAll($userID);
268 if ($entries) {
269 foreach($entries as $entry) {
270 $tags = $this->retrieveTagsByEntry($entry['id']);
271 foreach($tags as $tag) {
272 $this->removeTagForEntry($entry['id'], $tags);
273 }
274 $this->deleteById($entryid,$userID);
275 }
276 } else {
277 return false;
278 }
279 }
280
281 public function deleteUser($userID)
282 {
283 $sql_action = 'DELETE from users WHERE id=?';
284 $params_action = array($userID);
285 $query = $this->executeQuery($sql_action, $params_action);
286 }
287
288 public function updateContentAndTitle($id, $title, $body, $user_id)
289 {
290 $sql_action = 'UPDATE entries SET content = ?, title = ? WHERE id=? AND user_id=?';
291 $params_action = array($body, $title, $id, $user_id);
292 $query = $this->executeQuery($sql_action, $params_action);
293 return $query;
294 }
295
296 public function retrieveUnfetchedEntries($user_id, $limit)
297 {
298
299 $sql_limit = "LIMIT 0,".$limit;
300 if (STORAGE == 'postgres') {
301 $sql_limit = "LIMIT ".$limit." OFFSET 0";
302 }
303
304 $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=? ORDER BY id " . $sql_limit;
305 $query = $this->executeQuery($sql, array($user_id));
306 $entries = $query->fetchAll();
307
308 return ($query) ? $entries : false;
309 }
310
311 public function retrieveUnfetchedEntriesCount($user_id)
312 {
313 $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=?";
314 $query = $this->executeQuery($sql, array($user_id));
315 list($count) = $query->fetch();
316
317 return $count;
318 }
319
320 public function retrieveAll($user_id)
321 {
322 $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id";
323 $query = $this->executeQuery($sql, array($user_id));
324 $entries = $query->fetchAll();
325
326 return ($query) ? $entries : false;
327 }
328
329 public function retrieveAllWithTags($user_id)
330 {
331 $entries = $this->retrieveAll($user_id);
332 if ($entries) {
333 $count = count($entries);
334 for ($i = 0; $i < $count; $i++) {
335 $tag_entries = $this->retrieveTagsByEntry($entries[$i]['id']);
336 $tags = [];
337 foreach ($tag_entries as $tag) {
338 $tags[] = $tag[1];
339 }
340 $entries[$i]['tags'] = implode(',', $tags);
341 }
342 }
343 return $entries;
344 }
345
346 public function retrieveOneById($id, $user_id)
347 {
348 $sql = "SELECT * FROM entries WHERE id=? AND user_id=?";
349 $params = array(intval($id), $user_id);
350 $query = $this->executeQuery($sql, $params);
351 $entry = $query->fetchAll();
352
353 return ($query) ? $entry[0] : false;
354 }
355
356 public function retrieveOneByURL($url, $user_id)
357 {
358 $sql = "SELECT * FROM entries WHERE url=? AND user_id=?";
359 $params = array($url, $user_id);
360 $query = $this->executeQuery($sql, $params);
361 $entry = $query->fetchAll();
362
363 return ($query) ? $entry[0] : false;
364 }
365
366 public function reassignTags($old_entry_id, $new_entry_id)
367 {
368 $sql = "UPDATE tags_entries SET entry_id=? WHERE entry_id=?";
369 $params = array($new_entry_id, $old_entry_id);
370 $query = $this->executeQuery($sql, $params);
371 }
372
373 public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0)
374 {
375 switch ($view) {
376 case 'archive':
377 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
378 $params = array($user_id, 1);
379 break;
380 case 'fav' :
381 $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? ";
382 $params = array($user_id, 1);
383 break;
384 case 'tag' :
385 $sql = "SELECT entries.* FROM entries
386 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
387 WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
388 $params = array($user_id, $tag_id);
389 break;
390 default:
391 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
392 $params = array($user_id, 0);
393 break;
394 }
395
396 $sql .= $this->getEntriesOrder().' ' . $limit;
397
398 $query = $this->executeQuery($sql, $params);
399 $entries = $query->fetchAll();
400
401 return ($query) ? $entries : false;
402
403 }
404
405 public function getEntriesByViewCount($view, $user_id, $tag_id = 0)
406 {
407 switch ($view) {
408 case 'archive':
409 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
410 $params = array($user_id, 1);
411 break;
412 case 'fav' :
413 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? ";
414 $params = array($user_id, 1);
415 break;
416 case 'tag' :
417 $sql = "SELECT count(*) FROM entries
418 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
419 WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
420 $params = array($user_id, $tag_id);
421 break;
422 default:
423 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
424 $params = array($user_id, 0);
425 break;
426 }
427
428 $query = $this->executeQuery($sql, $params);
429 list($count) = ($query) ? $query->fetch() : array(false);
430
431 return $count;
432 }
433 public function getRandomId($user_id, $view) {
434 $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()';
435 switch ($view) {
436 case 'archive':
437 $sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1";
438 $params = array($user_id,1);
439 break;
440 case 'fav':
441 $sql = "SELECT id FROM entries WHERE user_id=? AND is_fav=? ORDER BY ". $random . " LIMIT 1";
442 $params = array($user_id,1);
443 break;
444 default:
445 $sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1";
446 $params = array($user_id,0);
447 break;
448 }
449 $query = $this->executeQuery($sql, $params);
450 $id = $query->fetchAll();
451
452 return ($query) ? $id : false;
453 }
454
455 public function getPreviousArticle($id, $user_id)
456 {
457 $sqlcondition = "is_read=0";
458 if (STORAGE == 'postgres') {
459 $sqlcondition = "is_read=false";
460 }
461 $sql = "SELECT id FROM entries WHERE id = (SELECT max(id) FROM entries WHERE id < ? AND " . $sqlcondition . ") AND user_id=? AND " . $sqlcondition;
462 $params = array($id, $user_id);
463 $query = $this->executeQuery($sql, $params);
464 $id_entry = ($query) ? $query->fetchAll() : false;
465 $id = ($query) ? $id_entry[0][0] : false;
466 return $id;
467 }
468
469 public function getNextArticle($id, $user_id)
470 {
471 $sqlcondition = "is_read=0";
472 if (STORAGE == 'postgres') {
473 $sqlcondition = "is_read=false";
474 }
475 $sql = "SELECT id FROM entries WHERE id = (SELECT min(id) FROM entries WHERE id > ? AND " . $sqlcondition . ") AND user_id=? AND " . $sqlcondition;
476 $params = array($id, $user_id);
477 $query = $this->executeQuery($sql, $params);
478 $id_entry = ($query) ? $query->fetchAll() : false;
479 $id = ($query) ? $id_entry[0][0] : false;
480 return $id;
481 }
482
483
484 public function updateContent($id, $content, $user_id)
485 {
486 $sql_action = 'UPDATE entries SET content = ? WHERE id=? AND user_id=?';
487 $params_action = array($content, $id, $user_id);
488 $query = $this->executeQuery($sql_action, $params_action);
489 return $query;
490 }
491
492 /**
493 *
494 * @param string $url
495 * @param string $title
496 * @param string $content
497 * @param integer $user_id
498 * @return integer $id of inserted record
499 */
500 public function add($url, $title, $content, $user_id, $isFavorite=0, $isRead=0)
501 {
502 $sql_action = 'INSERT INTO entries ( url, title, content, user_id, is_fav, is_read ) VALUES (?, ?, ?, ?, ?, ?)';
503 $params_action = array($url, $title, $content, $user_id, $isFavorite, $isRead);
504
505 if ( !$this->executeQuery($sql_action, $params_action) ) {
506 $id = null;
507 }
508 else {
509 $id = intval($this->getLastId( (STORAGE == 'postgres') ? 'entries_id_seq' : '') );
510 }
511 return $id;
512 }
513
514 public function deleteById($id, $user_id)
515 {
516 $sql_action = "DELETE FROM entries WHERE id=? AND user_id=?";
517 $params_action = array($id, $user_id);
518 $query = $this->executeQuery($sql_action, $params_action);
519 return $query;
520 }
521
522 public function favoriteById($id, $user_id)
523 {
524 $sql_action = "UPDATE entries SET is_fav=NOT is_fav WHERE id=? AND user_id=?";
525 $params_action = array($id, $user_id);
526 $query = $this->executeQuery($sql_action, $params_action);
527 }
528
529 public function archiveById($id, $user_id)
530 {
531 $sql_action = "UPDATE entries SET is_read=NOT is_read WHERE id=? AND user_id=?";
532 $params_action = array($id, $user_id);
533 $query = $this->executeQuery($sql_action, $params_action);
534 }
535
536 public function archiveAll($user_id)
537 {
538 $sql_action = "UPDATE entries SET is_read=? WHERE user_id=? AND is_read=?";
539 $params_action = array($user_id, 1, 0);
540 $query = $this->executeQuery($sql_action, $params_action);
541 }
542
543 public function getLastId($column = '')
544 {
545 return $this->getHandle()->lastInsertId($column);
546 }
547
548 public function search($term, $user_id, $limit = '')
549 {
550 $search = '%'.$term.'%';
551 $sql_action = "SELECT * FROM entries WHERE user_id=? AND (content LIKE ? OR title LIKE ? OR url LIKE ?) "; //searches in content, title and URL
552 $sql_action .= $this->getEntriesOrder().' ' . $limit;
553 $params_action = array($user_id, $search, $search, $search);
554 $query = $this->executeQuery($sql_action, $params_action);
555 return ($query) ? $query->fetchAll() : false;
556 }
557
558 public function retrieveAllTags($user_id, $term = NULL)
559 {
560 $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags
561 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
562 LEFT JOIN entries ON tags_entries.entry_id=entries.id
563 WHERE entries.user_id=?
564 ". (($term) ? "AND lower(tags.value) LIKE ?" : '') ."
565 GROUP BY tags.id, tags.value
566 ORDER BY tags.value";
567 $query = $this->executeQuery($sql, (($term)? array($user_id, strtolower('%'.$term.'%')) : array($user_id) ));
568 $tags = ($query) ? $query->fetchAll() : false;
569
570 return $tags;
571 }
572
573 public function retrieveTag($id, $user_id)
574 {
575 $sql = "SELECT DISTINCT tags.* FROM tags
576 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
577 LEFT JOIN entries ON tags_entries.entry_id=entries.id
578 WHERE tags.id=? AND entries.user_id=?";
579 $params = array(intval($id), $user_id);
580 $query = $this->executeQuery($sql, $params);
581 $tags = ($query) ? $query->fetchAll() : false;
582 $tag = ($query) ? $tags[0] : false;
583
584 return $tag[0];
585 }
586
587 public function retrieveEntriesByTag($tag_id, $user_id)
588 {
589 $sql =
590 "SELECT entries.* FROM entries
591 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
592 WHERE tags_entries.tag_id = ? AND entries.user_id=? ORDER by entries.id DESC";
593 $query = $this->executeQuery($sql, array($tag_id, $user_id));
594 $entries = ($query) ? $query->fetchAll() : false;
595
596 return $entries;
597 }
598
599 public function retrieveTagsByEntry($entry_id)
600 {
601 $sql =
602 "SELECT tags.* FROM tags
603 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
604 WHERE tags_entries.entry_id = ?";
605 $query = $this->executeQuery($sql, array($entry_id));
606 $tags = ($query) ? $query->fetchAll() : false;
607
608 return $tags;
609 }
610
611 public function removeTagForEntry($entry_id, $tag_id)
612 {
613 $sql_action = "DELETE FROM tags_entries WHERE tag_id=? AND entry_id=?";
614 $params_action = array($tag_id, $entry_id);
615 $query = $this->executeQuery($sql_action, $params_action);
616 return ($query) ? $query : false;
617 }
618
619 public function cleanUnusedTag($tag_id)
620 {
621 $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?";
622 $query = $this->executeQuery($sql_action,array($tag_id));
623 $tagstokeep = ($query) ? $query->fetchAll() : false;
624 $sql_action = "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?";
625 $query = $this->executeQuery($sql_action,array($tag_id));
626 $alltags = ($query) ? $query->fetchAll() : false;
627
628 if ($tagstokeep && $alltags) {
629 foreach ($alltags as $tag) {
630 if ($tag && !in_array($tag,$tagstokeep)) {
631 $sql_action = "DELETE FROM tags WHERE id=?";
632 $params_action = array($tag[0]);
633 $this->executeQuery($sql_action, $params_action);
634 return true;
635 }
636 }
637 } else {
638 return false;
639 }
640 }
641
642 public function retrieveTagByValue($value)
643 {
644 $sql = "SELECT * FROM tags WHERE value=?";
645 $params = array($value);
646 $query = $this->executeQuery($sql, $params);
647 $tag = ($query) ? $query->fetchAll() : false;
648
649 return ($query) ? $tag[0] : false;
650 }
651
652 public function createTag($value)
653 {
654 $sql_action = 'INSERT INTO tags ( value ) VALUES (?)';
655 $params_action = array($value);
656 $query = $this->executeQuery($sql_action, $params_action);
657 return ($query) ? $query : false;
658 }
659
660 public function setTagToEntry($tag_id, $entry_id)
661 {
662 $sql_action = 'INSERT INTO tags_entries ( tag_id, entry_id ) VALUES (?, ?)';
663 $params_action = array($tag_id, $entry_id);
664 $query = $this->executeQuery($sql_action, $params_action);
665 return ($query) ? $query : false;
666 }
667
668 private function getEntriesOrder()
669 {
670 if (isset($_SESSION['sort']) and array_key_exists($_SESSION['sort'], $this->order)) {
671 return $this->order[$_SESSION['sort']];
672 }
673 else {
674 return $this->order['default'];
675 }
676 }
677 }