1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-23 17:42:15 -05:00

a lot of refactoring: tag action is now handled by home view and uses sorting and pagination. Some small view enhacenments. Fix of #476, #461 for baggy and other themes

This commit is contained in:
Maryana Rozhankivska 2014-02-20 19:28:39 +02:00
parent 6203ef8e51
commit 032e0ca13a
15 changed files with 143 additions and 130 deletions

83
inc/poche/Database.class.php Normal file → Executable file
View File

@ -10,6 +10,13 @@
class Database {
var $handle;
private $order = array(
'ia' => 'ORDER BY entries.id',
'id' => 'ORDER BY entries.id DESC',
'ta' => 'ORDER BY lower(entries.title)',
'td' => 'ORDER BY lower(entries.title) DESC',
'default' => 'ORDER BY entries.id'
);
function __construct()
{
@ -257,43 +264,29 @@ class Database {
$query = $this->executeQuery($sql, $params);
}
public function getEntriesByView($view, $user_id, $limit = '') {
switch ($_SESSION['sort'])
{
case 'ia':
$order = 'ORDER BY id';
break;
case 'id':
$order = 'ORDER BY id DESC';
break;
case 'ta':
$order = 'ORDER BY lower(title)';
break;
case 'td':
$order = 'ORDER BY lower(title) DESC';
break;
default:
$order = 'ORDER BY id';
break;
}
switch ($view)
{
public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) {
switch ($view) {
case 'archive':
$sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order;
$sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
$params = array($user_id, 1);
break;
case 'fav' :
$sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? " . $order;
$sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? ";
$params = array($user_id, 1);
break;
case 'tag' :
$sql = "SELECT entries.* FROM entries
LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
$params = array($user_id, $tag_id);
break;
default:
$sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order;
$sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
$params = array($user_id, 0);
break;
}
$sql .= ' ' . $limit;
$sql .= $this->getEntriesOrder().' ' . $limit;
$query = $this->executeQuery($sql, $params);
$entries = $query->fetchAll();
@ -301,6 +294,34 @@ class Database {
return $entries;
}
public function getEntriesByViewCount($view, $user_id, $tag_id = 0) {
switch ($view) {
case 'archive':
$sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
$params = array($user_id, 1);
break;
case 'fav' :
$sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? ";
$params = array($user_id, 1);
break;
case 'tag' :
$sql = "SELECT count(*) FROM entries
LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
$params = array($user_id, $tag_id);
break;
default:
$sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
$params = array($user_id, 0);
break;
}
$query = $this->executeQuery($sql, $params);
list($count) = $query->fetch();
return $count;
}
public function updateContent($id, $content, $user_id) {
$sql_action = 'UPDATE entries SET content = ? WHERE id=? AND user_id=?';
$params_action = array($content, $id, $user_id);
@ -420,4 +441,14 @@ class Database {
$query = $this->executeQuery($sql_action, $params_action);
return $query;
}
private function getEntriesOrder() {
if (isset($_SESSION['sort']) and array_key_exists($_SESSION['sort'], $this->order)) {
return $this->order[$_SESSION['sort']];
}
else {
return $this->order['default'];
}
}
}

View File

@ -585,14 +585,7 @@ class Poche
$tpl_vars = array(
'entry_id' => $id,
'tags' => $tags,
);
break;
case 'tag':
$entries = $this->store->retrieveEntriesByTag($id, $this->user->getId());
$tag = $this->store->retrieveTag($id, $this->user->getId());
$tpl_vars = array(
'tag' => $tag,
'entries' => $entries,
'entry' => $entry,
);
break;
case 'tags':
@ -633,22 +626,28 @@ class Poche
Tools::logm('error in view call : entry is null');
}
break;
default: # home, favorites and archive views
$entries = $this->store->getEntriesByView($view, $this->user->getId());
default: # home, favorites, archive and tag views
$tpl_vars = array(
'entries' => '',
'page_links' => '',
'nb_results' => '',
);
if (count($entries) > 0) {
$this->pagination->set_total(count($entries));
//if id is given - we retrive entries by tag: id is tag id
if ($id) {
$tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId());
$tpl_vars['id'] = intval($id);
}
$count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id);
if ($count > 0) {
$this->pagination->set_total($count);
$page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')),
$this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&'));
$datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit());
$tpl_vars['entries'] = $datas;
$this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . (($id)?'&id='.$id:'') . '&' ));
$tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id);
$tpl_vars['page_links'] = $page_links;
$tpl_vars['nb_results'] = count($entries);
$tpl_vars['nb_results'] = $count;
}
Tools::logm('display ' . $view . ' view');
break;

View File

@ -92,7 +92,7 @@ class Tools
{
$views = array(
'install', 'import', 'export', 'config', 'tags',
'edit-tags', 'view', 'login', 'error', 'tag'
'edit-tags', 'view', 'login', 'error'
);
if (in_array($view, $views)) {

View File

@ -4,6 +4,9 @@
<li><a href="./?view=fav" {% if view == 'fav' %}class="current"{% endif %}>{% trans "favorites" %}</a></li>
<li><a href="./?view=archive" {% if view == 'archive' %}class="current"{% endif %}>{% trans "archive" %}</a></li>
<li><a href="./?view=tags" {% if view == 'tags' %}class="current"{% endif %}>{% trans "tags" %}</a></li>
<li><a href="javascript: void(null);" id="pocheit">{% trans "save a link" %}</a></li>
<li><a href="./?view=config" {% if view == 'config' %}class="current"{% endif %}>{% trans "config" %}</a></li>
<li><a class="icon icon-power" href="./?logout" title="{% trans "logout" %}">{% trans "logout" %}</a></li>
</ul>
{% include '_pocheit-form.twig' %}

View File

@ -563,7 +563,8 @@ footer a {
========================================================================== */
.messages {
text-align: center;
text-align: left;
margin-top: 1em;
}
.messages > * { display: inline-block;}

View File

@ -4,6 +4,9 @@
{% include '_menu.twig' %}
{% endblock %}
{% block content %}
<div id="article">
<h2>{{ entry.title|raw }}</21>
</div>
{% if tags is empty %}
<div class="notags">no tags</div>
{% endif %}
@ -11,10 +14,10 @@
{% for tag in tags %}<li>{{ tag.value }} <a href="./?action=remove_tag&amp;tag_id={{ tag.id }}&amp;id={{ entry_id }}">✘</a></li>{% endfor %}
</ul>
<form method="post" action="./?action=add_tag">
<label for="value">Add tags: </label><input type="text" placeholder="interview, editorial, video" id="value" name="value" required="required" />
<p>{% trans "You can enter multiple tags, separated by commas." %}</p>
<input type="hidden" name="entry_id" value="{{ entry_id }}" />
<label for="value">Add tags: </label><input type="text" placeholder="interview, editorial, video" id="value" name="value" required="required" />
<input type="submit" value="Tag" />
<p>{% trans "You can enter multiple tags, separated by commas." %}</p>
</form>
<a class="icon icon-reply return" href="./?view=view&id={{ entry_id }}">{% trans "return to article" %}</a>
{% endblock %}

View File

@ -12,6 +12,9 @@
{% include '_menu.twig' %}
{% endblock %}
{% block content %}
{% if tag %}
<h3>{% trans "Tag" %}: <b>{{ tag.value }}</b></h3>
{% endif %}
{% if entries is empty %}
<div class="messages warning"><p>{% trans "No articles found." %}</p></div>
{% else %}

View File

@ -1,34 +0,0 @@
{% extends "layout.twig" %}
{% block title %}tag {% endblock %}
{% block menu %}
{% include '_menu.twig' %}
{% endblock %}
{% block content %}
<h3>{% trans "Tag" %} {{ tag.value }}</h3>
{% if entries is empty %}
<div class="messages warning"><p>{% trans "No link available here!" %}</p></div>
{% else %}
{% block pager %}
{% if nb_results > 1 %}
<div class="results">
<div class="nb-results">{{ nb_results }} {% trans "results" %}</div>
{{ page_links | raw }}
</div>
{% endif %}
{% endblock %}
<div class="list-entries">
{% for entry in entries %}
<div id="entry-{{ entry.id|e }}" class="entrie">
<h2><a href="index.php?view=view&amp;id={{ entry.id|e }}">{{ entry.title|raw }}</a></h2>
<ul class="tools links">
<li><a title="{% trans "Toggle mark as read" %}" class="tool icon-check icon {% if entry.is_read == 0 %}archive-off{% else %}archive{% endif %}" href="./?action=toggle_archive&amp;id={{ entry.id|e }}"><span>{% trans "Toggle mark as read" %}</span></a></li>
<li><a title="{% trans "toggle favorite" %}" class="tool icon-star icon {% if entry.is_fav == 0 %}fav-off{% else %}fav{% endif %}" href="./?action=toggle_fav&amp;id={{ entry.id|e }}"><span>{% trans "toggle favorite" %}</span></a></li>
<li><a title="{% trans "delete" %}" class="tool delete icon-trash icon" href="./?action=delete&amp;id={{ entry.id|e }}"><span>{% trans "delete" %}</span></a></li>
<li><a href="{{ entry.url|e }}" target="_blank" title="{% trans "original" %} : {{ entry.title|e }}" class="tool link icon-link icon"><span>{{ entry.url | e | getDomain }}</span></a></li>
</ul>
<p>{{ entry.content|striptags|slice(0, 300) }}...</p>
</div>
{% endfor %}
</div>
{% endif %}
{% endblock %}

View File

@ -14,8 +14,8 @@
{% block precontent %}
{% if entries|length > 1 %}
<ul id="sort">
<li><a href="./?sort=ia&amp;view={{ view }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by date asc" %}" title="{% trans "by date asc" %}" /></a> {% trans "by date" %} <a href="./?sort=id&amp;view={{ view }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by date desc" %}" title="{% trans "by date desc" %}" /></a></li>
<li><a href="./?sort=ta&amp;view={{ view }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by title asc" %}" title="{% trans "by title asc" %}" /></a> {% trans "by title" %} <a href="./?sort=td&amp;view={{ view }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by title desc" %}" title="{% trans "by title desc" %}" /></a></li>
<li><a href="./?sort=ia&amp;view={{ view }}&amp;id={{ id }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by date asc" %}" title="{% trans "by date asc" %}" /></a> {% trans "by date" %} <a href="./?sort=id&amp;view={{ view }}&amp;id={{ id }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by date desc" %}" title="{% trans "by date desc" %}" /></a></li>
<li><a href="./?sort=ta&amp;view={{ view }}&amp;id={{ id }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by title asc" %}" title="{% trans "by title asc" %}" /></a> {% trans "by title" %} <a href="./?sort=td&amp;view={{ view }}&amp;id={{ id }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by title desc" %}" title="{% trans "by title desc" %}" /></a></li>
</ul>
{% endif %}
{% endblock %}

View File

@ -4,6 +4,13 @@
{% include '_menu.twig' %}
{% endblock %}
{% block content %}
<div id="article">
<header class="mbm">
<h1>{{ entry.title|raw }}</h1>
</header>
</div>
{% if tags is empty %}
no tags
{% endif %}
@ -11,10 +18,12 @@ no tags
{% for tag in tags %}<li>{{ tag.value }} <a href="./?action=remove_tag&amp;tag_id={{ tag.id }}&amp;id={{ entry_id }}">✘</a></li>{% endfor %}
</ul>
<form method="post" action="./?action=add_tag">
<label for="value">Add tags: </label><input type="text" placeholder="interview, editorial, video" id="value" name="value" required="required" />
<p>{% trans "You can enter multiple tags, separated by commas." %}</p>
<input type="hidden" name="entry_id" value="{{ entry_id }}" />
<label for="value">Add tags: </label>
<input type="text" placeholder="interview, editorial, video" id="value" name="value" required="required" />
<input type="submit" value="Tag" />
<p>{% trans "You can enter multiple tags, separated by commas." %}</p>
</form>
<a href="./?view=view&id={{ entry_id }}">{% trans "return to article" %}</a>
<a href="./?view=view&id={{ entry_id }}">&laquo; {% trans "return to article" %}</a>
{% endblock %}

View File

@ -14,12 +14,16 @@
{% block precontent %}
{% if entries|length > 1 %}
<ul id="sort">
<li><a href="./?sort=ia&amp;view={{ view }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by date asc" %}" title="{% trans "by date asc" %}" /></a> {% trans "by date" %} <a href="./?sort=id&amp;view={{ view }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by date desc" %}" title="{% trans "by date desc" %}" /></a></li>
<li><a href="./?sort=ta&amp;view={{ view }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by title asc" %}" title="{% trans "by title asc" %}" /></a> {% trans "by title" %} <a href="./?sort=td&amp;view={{ view }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by title desc" %}" title="{% trans "by title desc" %}" /></a></li>
<li><a href="./?sort=ia&amp;view={{ view }}&amp;id={{ id }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by date asc" %}" title="{% trans "by date asc" %}" /></a> {% trans "by date" %} <a href="./?sort=id&amp;view={{ view }}&amp;id={{ id }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by date desc" %}" title="{% trans "by date desc" %}" /></a></li>
<li><a href="./?sort=ta&amp;view={{ view }}&amp;id={{ id }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by title asc" %}" title="{% trans "by title asc" %}" /></a> {% trans "by title" %} <a href="./?sort=td&amp;view={{ view }}&amp;id={{ id }}"><img src="{{ poche_url }}/themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by title desc" %}" title="{% trans "by title desc" %}" /></a></li>
</ul>
{% endif %}
{% endblock %}
{% block content %}
{% if tag %}
<h3>{% trans "Tag" %}: <b>{{ tag.value }}</b></h3>
{% endif %}
{% if entries is empty %}
<div class="messages warning"><p>{% trans "No articles found." %}</p></div>
{% else %}

View File

@ -1,33 +0,0 @@
{% extends "layout.twig" %}
{% block title %}tag {% endblock %}
{% block menu %}
{% include '_menu.twig' %}
{% endblock %}
{% block content %}
<h3>{% trans "Tag" %} {{ tag.value }}</h3>
{% if entries is empty %}
<div class="messages warning"><p>{% trans "No link available here!" %}</p></div>
{% else %}
{% block pager %}
{% if nb_results > 1 %}
<div class="results">
<div class="nb-results">{{ nb_results }} {% trans "results" %}</div>
{{ page_links | raw }}
</div>
{% endif %}
{% endblock %}
{% for entry in entries %}
<div id="entry-{{ entry.id|e }}" class="entrie">
<h2><a href="index.php?view=view&amp;id={{ entry.id|e }}">{{ entry.title|raw }}</a></h2>
<ul class="tools">
<li><a title="{% trans "toggle mark as read" %}" class="tool {% if entry.is_read == 0 %}archive-off{% else %}archive{% endif %}" href="./?action=toggle_archive&amp;id={{ entry.id|e }}"><span>{% trans "toggle mark as read" %}</span></a></li>
<li><a title="{% trans "toggle favorite" %}" class="tool {% if entry.is_fav == 0 %}fav-off{% else %}fav{% endif %}" href="./?action=toggle_fav&amp;id={{ entry.id|e }}"><span>{% trans "toggle favorite" %}</span></a></li>
<li><a title="{% trans "delete" %}" class="tool delete" href="./?action=delete&amp;id={{ entry.id|e }}"><span>{% trans "delete" %}</span></a></li>
<li><a href="{{ entry.url|e }}" target="_blank" title="{% trans "original" %} : {{ entry.title|e }}" class="tool link"><span>{{ entry.url | e | getDomain }}</span></a></li>
<li><a target="_blank" title="{% trans "estimated reading time:" %} {{ entry.content| getReadingTime }} min" class="reading-time"><span>{{ entry.content| getReadingTime }} min</span></a></li>
</ul>
<p>{{ entry.content|striptags|slice(0, 300) }}...</p>
</div>
{% endfor %}
{% endif %}
{% endblock %}

View File

@ -20,12 +20,15 @@
<header class="mbm">
<h1>{{ entry.title|raw }}</h1>
</header>
{% block tags %}
<aside class="tags">
{% trans "tags:" %} {% for tag in tags %}<a href="./?view=tag&amp;id={{ tag.id }}">{{ tag.value }}</a> {% endfor %}<a href="./?view=edit-tags&amp;id={{ entry.id|e }}" title="{% trans "Edit tags" %}">✎</a>
</aside>
{% endblock %}
<article>
{{ content | raw }}
</article>
{{ block('tags') }}
</div>
<script src="{{ poche_url }}/themes/{{ constant('DEFAULT_THEME') }}/js/restoreScroll.js"></script>
<script type="text/javascript">

View File

@ -218,3 +218,15 @@ a.link span {
a.bad-display span {
background-image: url('../img/solarized-dark/bad-display.png');
}
.arrow-down {
width: 0px;
height: 0px;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #586E75 transparent transparent transparent;
position: absolute;
margin-top: 1.5em;
margin-left: -30px;
}

View File

@ -218,3 +218,15 @@ a.link span {
a.bad-display span {
background-image: url('../img/solarized/bad-display.png');
}
.arrow-down {
width: 0px;
height: 0px;
border-style: solid;
border-width: 10px 10px 0 10px;
border-color: #93A1A1 transparent transparent transparent;
position: absolute;
margin-top: 1.5em;
margin-left: -30px;
}