mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
commit
05d6dd487c
14 changed files with 252 additions and 41 deletions
|
@ -249,4 +249,75 @@ class Database {
|
|||
public function getLastId($column = '') {
|
||||
return $this->getHandle()->lastInsertId($column);
|
||||
}
|
||||
|
||||
public function retrieveAllTags() {
|
||||
$sql = "SELECT * FROM tags";
|
||||
$query = $this->executeQuery($sql, array());
|
||||
$tags = $query->fetchAll();
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
public function retrieveTag($id) {
|
||||
$tag = NULL;
|
||||
$sql = "SELECT * FROM tags WHERE id=?";
|
||||
$params = array(intval($id));
|
||||
$query = $this->executeQuery($sql, $params);
|
||||
$tag = $query->fetchAll();
|
||||
|
||||
return isset($tag[0]) ? $tag[0] : null;
|
||||
}
|
||||
|
||||
public function retrieveEntriesByTag($tag_id) {
|
||||
$sql =
|
||||
"SELECT * FROM entries
|
||||
LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
|
||||
WHERE tags_entries.tag_id = ?";
|
||||
$query = $this->executeQuery($sql, array($tag_id));
|
||||
$entries = $query->fetchAll();
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
public function retrieveTagsByEntry($entry_id) {
|
||||
$sql =
|
||||
"SELECT * FROM tags
|
||||
LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
|
||||
WHERE tags_entries.entry_id = ?";
|
||||
$query = $this->executeQuery($sql, array($entry_id));
|
||||
$tags = $query->fetchAll();
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
public function removeTagForEntry($entry_id, $tag_id) {
|
||||
$sql_action = "DELETE FROM tags_entries WHERE tag_id=? AND entry_id=?";
|
||||
$params_action = array($tag_id, $entry_id);
|
||||
$query = $this->executeQuery($sql_action, $params_action);
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function retrieveTagByValue($value) {
|
||||
$tag = NULL;
|
||||
$sql = "SELECT * FROM tags WHERE value=?";
|
||||
$params = array($value);
|
||||
$query = $this->executeQuery($sql, $params);
|
||||
$tag = $query->fetchAll();
|
||||
|
||||
return isset($tag[0]) ? $tag[0] : null;
|
||||
}
|
||||
|
||||
public function createTag($value) {
|
||||
$sql_action = 'INSERT INTO tags ( value ) VALUES (?)';
|
||||
$params_action = array($value);
|
||||
$query = $this->executeQuery($sql_action, $params_action);
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function setTagToEntry($tag_id, $entry_id) {
|
||||
$sql_action = 'INSERT INTO tags_entries ( tag_id, entry_id ) VALUES (?, ?)';
|
||||
$params_action = array($tag_id, $entry_id);
|
||||
$query = $this->executeQuery($sql_action, $params_action);
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -397,6 +397,36 @@ class Poche
|
|||
Tools::redirect();
|
||||
}
|
||||
break;
|
||||
case 'add_tag' :
|
||||
$tags = explode(',', $_POST['value']);
|
||||
$entry_id = $_POST['entry_id'];
|
||||
foreach($tags as $key => $tag_value) {
|
||||
$value = trim($tag_value);
|
||||
$tag = $this->store->retrieveTagByValue($value);
|
||||
|
||||
if (is_null($tag)) {
|
||||
# we create the tag
|
||||
$tag = $this->store->createTag($value);
|
||||
$sequence = '';
|
||||
if (STORAGE == 'postgres') {
|
||||
$sequence = 'tags_id_seq';
|
||||
}
|
||||
$tag_id = $this->store->getLastId($sequence);
|
||||
}
|
||||
else {
|
||||
$tag_id = $tag['id'];
|
||||
}
|
||||
|
||||
# we assign the tag to the article
|
||||
$this->store->setTagToEntry($tag_id, $entry_id);
|
||||
}
|
||||
Tools::redirect();
|
||||
break;
|
||||
case 'remove_tag' :
|
||||
$tag_id = $_GET['tag_id'];
|
||||
$this->store->removeTagForEntry($id, $tag_id);
|
||||
Tools::redirect();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -430,6 +460,31 @@ class Poche
|
|||
);
|
||||
Tools::logm('config view');
|
||||
break;
|
||||
case 'edit-tags':
|
||||
# tags
|
||||
$tags = $this->store->retrieveTagsByEntry($id);
|
||||
$tpl_vars = array(
|
||||
'entry_id' => $id,
|
||||
'tags' => $tags,
|
||||
);
|
||||
break;
|
||||
case 'tag':
|
||||
$entries = $this->store->retrieveEntriesByTag($id);
|
||||
$tag = $this->store->retrieveTag($id);
|
||||
$tpl_vars = array(
|
||||
'tag' => $tag,
|
||||
'entries' => $entries,
|
||||
);
|
||||
break;
|
||||
case 'tags':
|
||||
$token = $this->user->getConfigValue('token');
|
||||
$tags = $this->store->retrieveAllTags();
|
||||
$tpl_vars = array(
|
||||
'token' => $token,
|
||||
'user_id' => $this->user->getId(),
|
||||
'tags' => $tags,
|
||||
);
|
||||
break;
|
||||
case 'view':
|
||||
$entry = $this->store->retrieveOneById($id, $this->user->getId());
|
||||
if ($entry != NULL) {
|
||||
|
@ -443,12 +498,16 @@ class Poche
|
|||
|
||||
# flattr checking
|
||||
$flattr = new FlattrItem();
|
||||
$flattr->checkItem($entry['url'],$entry['id']);
|
||||
$flattr->checkItem($entry['url'], $entry['id']);
|
||||
|
||||
# tags
|
||||
$tags = $this->store->retrieveTagsByEntry($entry['id']);
|
||||
|
||||
$tpl_vars = array(
|
||||
'entry' => $entry,
|
||||
'content' => $content,
|
||||
'flattr' => $flattr
|
||||
'entry' => $entry,
|
||||
'content' => $content,
|
||||
'flattr' => $flattr,
|
||||
'tags' => $tags
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -859,9 +918,9 @@ class Poche
|
|||
$_SESSION['poche_user']->setConfig($currentConfig);
|
||||
}
|
||||
|
||||
public function generateFeeds($token, $user_id, $type = 'home')
|
||||
public function generateFeeds($token, $user_id, $tag_id, $type = 'home')
|
||||
{
|
||||
$allowed_types = array('home', 'fav', 'archive');
|
||||
$allowed_types = array('home', 'fav', 'archive', 'tag');
|
||||
$config = $this->store->getConfigUser($user_id);
|
||||
|
||||
if (!in_array($type, $allowed_types) ||
|
||||
|
@ -876,7 +935,13 @@ class Poche
|
|||
$feed->setChannelElement('updated', date(DATE_RSS , time()));
|
||||
$feed->setChannelElement('author', 'poche');
|
||||
|
||||
$entries = $this->store->getEntriesByView($type, $user_id);
|
||||
if ($type == 'tag') {
|
||||
$entries = $this->store->retrieveEntriesByTag($tag_id);
|
||||
}
|
||||
else {
|
||||
$entries = $this->store->getEntriesByView($type, $user_id);
|
||||
}
|
||||
|
||||
if (count($entries) > 0) {
|
||||
foreach ($entries as $entry) {
|
||||
$newItem = $feed->createNewItem();
|
||||
|
|
|
@ -88,39 +88,16 @@ class Tools
|
|||
|
||||
public static function getTplFile($view)
|
||||
{
|
||||
$default_tpl = 'home.twig';
|
||||
|
||||
switch ($view) {
|
||||
case 'install':
|
||||
$tpl_file = 'install.twig';
|
||||
break;
|
||||
case 'import';
|
||||
$tpl_file = 'import.twig';
|
||||
break;
|
||||
case 'export':
|
||||
$tpl_file = 'export.twig';
|
||||
break;
|
||||
case 'config':
|
||||
$tpl_file = 'config.twig';
|
||||
break;
|
||||
case 'view':
|
||||
$tpl_file = 'view.twig';
|
||||
break;
|
||||
|
||||
case 'login':
|
||||
$tpl_file = 'login.twig';
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
$tpl_file = 'error.twig';
|
||||
break;
|
||||
|
||||
default:
|
||||
$tpl_file = $default_tpl;
|
||||
break;
|
||||
$views = array(
|
||||
'install', 'import', 'export', 'config', 'tags',
|
||||
'edit-tags', 'view', 'login', 'error', 'tag'
|
||||
);
|
||||
|
||||
if (in_array($view, $views)) {
|
||||
return $view . '.twig';
|
||||
}
|
||||
|
||||
return $tpl_file;
|
||||
|
||||
return 'home.twig';
|
||||
}
|
||||
|
||||
public static function getFile($url)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue