aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/poche/Database.class.php71
-rw-r--r--inc/poche/Poche.class.php79
-rw-r--r--inc/poche/Tools.class.php41
3 files changed, 152 insertions, 39 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index c233eda1..d95b9b81 100644
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -249,4 +249,75 @@ class Database {
249 public function getLastId($column = '') { 249 public function getLastId($column = '') {
250 return $this->getHandle()->lastInsertId($column); 250 return $this->getHandle()->lastInsertId($column);
251 } 251 }
252
253 public function retrieveAllTags() {
254 $sql = "SELECT * FROM tags";
255 $query = $this->executeQuery($sql, array());
256 $tags = $query->fetchAll();
257
258 return $tags;
259 }
260
261 public function retrieveTag($id) {
262 $tag = NULL;
263 $sql = "SELECT * FROM tags WHERE id=?";
264 $params = array(intval($id));
265 $query = $this->executeQuery($sql, $params);
266 $tag = $query->fetchAll();
267
268 return isset($tag[0]) ? $tag[0] : null;
269 }
270
271 public function retrieveEntriesByTag($tag_id) {
272 $sql =
273 "SELECT * FROM entries
274 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
275 WHERE tags_entries.tag_id = ?";
276 $query = $this->executeQuery($sql, array($tag_id));
277 $entries = $query->fetchAll();
278
279 return $entries;
280 }
281
282 public function retrieveTagsByEntry($entry_id) {
283 $sql =
284 "SELECT * FROM tags
285 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
286 WHERE tags_entries.entry_id = ?";
287 $query = $this->executeQuery($sql, array($entry_id));
288 $tags = $query->fetchAll();
289
290 return $tags;
291 }
292
293 public function removeTagForEntry($entry_id, $tag_id) {
294 $sql_action = "DELETE FROM tags_entries WHERE tag_id=? AND entry_id=?";
295 $params_action = array($tag_id, $entry_id);
296 $query = $this->executeQuery($sql_action, $params_action);
297 return $query;
298 }
299
300 public function retrieveTagByValue($value) {
301 $tag = NULL;
302 $sql = "SELECT * FROM tags WHERE value=?";
303 $params = array($value);
304 $query = $this->executeQuery($sql, $params);
305 $tag = $query->fetchAll();
306
307 return isset($tag[0]) ? $tag[0] : null;
308 }
309
310 public function createTag($value) {
311 $sql_action = 'INSERT INTO tags ( value ) VALUES (?)';
312 $params_action = array($value);
313 $query = $this->executeQuery($sql_action, $params_action);
314 return $query;
315 }
316
317 public function setTagToEntry($tag_id, $entry_id) {
318 $sql_action = 'INSERT INTO tags_entries ( tag_id, entry_id ) VALUES (?, ?)';
319 $params_action = array($tag_id, $entry_id);
320 $query = $this->executeQuery($sql_action, $params_action);
321 return $query;
322 }
252} 323}
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index d45d0c40..d415dd03 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -397,6 +397,36 @@ class Poche
397 Tools::redirect(); 397 Tools::redirect();
398 } 398 }
399 break; 399 break;
400 case 'add_tag' :
401 $tags = explode(',', $_POST['value']);
402 $entry_id = $_POST['entry_id'];
403 foreach($tags as $key => $tag_value) {
404 $value = trim($tag_value);
405 $tag = $this->store->retrieveTagByValue($value);
406
407 if (is_null($tag)) {
408 # we create the tag
409 $tag = $this->store->createTag($value);
410 $sequence = '';
411 if (STORAGE == 'postgres') {
412 $sequence = 'tags_id_seq';
413 }
414 $tag_id = $this->store->getLastId($sequence);
415 }
416 else {
417 $tag_id = $tag['id'];
418 }
419
420 # we assign the tag to the article
421 $this->store->setTagToEntry($tag_id, $entry_id);
422 }
423 Tools::redirect();
424 break;
425 case 'remove_tag' :
426 $tag_id = $_GET['tag_id'];
427 $this->store->removeTagForEntry($id, $tag_id);
428 Tools::redirect();
429 break;
400 default: 430 default:
401 break; 431 break;
402 } 432 }
@@ -430,6 +460,31 @@ class Poche
430 ); 460 );
431 Tools::logm('config view'); 461 Tools::logm('config view');
432 break; 462 break;
463 case 'edit-tags':
464 # tags
465 $tags = $this->store->retrieveTagsByEntry($id);
466 $tpl_vars = array(
467 'entry_id' => $id,
468 'tags' => $tags,
469 );
470 break;
471 case 'tag':
472 $entries = $this->store->retrieveEntriesByTag($id);
473 $tag = $this->store->retrieveTag($id);
474 $tpl_vars = array(
475 'tag' => $tag,
476 'entries' => $entries,
477 );
478 break;
479 case 'tags':
480 $token = $this->user->getConfigValue('token');
481 $tags = $this->store->retrieveAllTags();
482 $tpl_vars = array(
483 'token' => $token,
484 'user_id' => $this->user->getId(),
485 'tags' => $tags,
486 );
487 break;
433 case 'view': 488 case 'view':
434 $entry = $this->store->retrieveOneById($id, $this->user->getId()); 489 $entry = $this->store->retrieveOneById($id, $this->user->getId());
435 if ($entry != NULL) { 490 if ($entry != NULL) {
@@ -443,12 +498,16 @@ class Poche
443 498
444 # flattr checking 499 # flattr checking
445 $flattr = new FlattrItem(); 500 $flattr = new FlattrItem();
446 $flattr->checkItem($entry['url'],$entry['id']); 501 $flattr->checkItem($entry['url'], $entry['id']);
502
503 # tags
504 $tags = $this->store->retrieveTagsByEntry($entry['id']);
447 505
448 $tpl_vars = array( 506 $tpl_vars = array(
449 'entry' => $entry, 507 'entry' => $entry,
450 'content' => $content, 508 'content' => $content,
451 'flattr' => $flattr 509 'flattr' => $flattr,
510 'tags' => $tags
452 ); 511 );
453 } 512 }
454 else { 513 else {
@@ -859,9 +918,9 @@ class Poche
859 $_SESSION['poche_user']->setConfig($currentConfig); 918 $_SESSION['poche_user']->setConfig($currentConfig);
860 } 919 }
861 920
862 public function generateFeeds($token, $user_id, $type = 'home') 921 public function generateFeeds($token, $user_id, $tag_id, $type = 'home')
863 { 922 {
864 $allowed_types = array('home', 'fav', 'archive'); 923 $allowed_types = array('home', 'fav', 'archive', 'tag');
865 $config = $this->store->getConfigUser($user_id); 924 $config = $this->store->getConfigUser($user_id);
866 925
867 if (!in_array($type, $allowed_types) || 926 if (!in_array($type, $allowed_types) ||
@@ -876,7 +935,13 @@ class Poche
876 $feed->setChannelElement('updated', date(DATE_RSS , time())); 935 $feed->setChannelElement('updated', date(DATE_RSS , time()));
877 $feed->setChannelElement('author', 'poche'); 936 $feed->setChannelElement('author', 'poche');
878 937
879 $entries = $this->store->getEntriesByView($type, $user_id); 938 if ($type == 'tag') {
939 $entries = $this->store->retrieveEntriesByTag($tag_id);
940 }
941 else {
942 $entries = $this->store->getEntriesByView($type, $user_id);
943 }
944
880 if (count($entries) > 0) { 945 if (count($entries) > 0) {
881 foreach ($entries as $entry) { 946 foreach ($entries as $entry) {
882 $newItem = $feed->createNewItem(); 947 $newItem = $feed->createNewItem();
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index 9d8e1fd6..63916582 100644
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -88,39 +88,16 @@ class Tools
88 88
89 public static function getTplFile($view) 89 public static function getTplFile($view)
90 { 90 {
91 $default_tpl = 'home.twig'; 91 $views = array(
92 92 'install', 'import', 'export', 'config', 'tags',
93 switch ($view) { 93 'edit-tags', 'view', 'login', 'error', 'tag'
94 case 'install': 94 );
95 $tpl_file = 'install.twig'; 95
96 break; 96 if (in_array($view, $views)) {
97 case 'import'; 97 return $view . '.twig';
98 $tpl_file = 'import.twig';
99 break;
100 case 'export':
101 $tpl_file = 'export.twig';
102 break;
103 case 'config':
104 $tpl_file = 'config.twig';
105 break;
106 case 'view':
107 $tpl_file = 'view.twig';
108 break;
109
110 case 'login':
111 $tpl_file = 'login.twig';
112 break;
113
114 case 'error':
115 $tpl_file = 'error.twig';
116 break;
117
118 default:
119 $tpl_file = $default_tpl;
120 break;
121 } 98 }
122 99
123 return $tpl_file; 100 return 'home.twig';
124 } 101 }
125 102
126 public static function getFile($url) 103 public static function getFile($url)