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

stockage de la vue et du tri en session

This commit is contained in:
nicosomb 2013-04-16 11:52:25 +02:00
parent 643e3037e6
commit 139769aa24
8 changed files with 99 additions and 88 deletions

View File

@ -17,6 +17,7 @@ require_once 'rain.tpl.class.php';
$db = new db(DB_PATH); $db = new db(DB_PATH);
# Initialisation de RainTPL
raintpl::$tpl_dir = './tpl/'; raintpl::$tpl_dir = './tpl/';
raintpl::$cache_dir = './cache/'; raintpl::$cache_dir = './cache/';
raintpl::$base_url = get_poche_url(); raintpl::$base_url = get_poche_url();
@ -24,6 +25,7 @@ raintpl::configure('path_replace', false);
raintpl::configure('debug', false); raintpl::configure('debug', false);
$tpl = new raintpl(); $tpl = new raintpl();
# Démarrage session et initialisation du jeton de sécurité
session_start(); session_start();
if (!isset($_SESSION['token_poche'])) { if (!isset($_SESSION['token_poche'])) {
@ -31,3 +33,15 @@ if (!isset($_SESSION['token_poche'])) {
$_SESSION['token_poche'] = $token; $_SESSION['token_poche'] = $token;
$_SESSION['token_time_poche'] = time(); $_SESSION['token_time_poche'] = time();
} }
# Traitement des paramètres et déclenchement des actions
$action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : '';
$_SESSION['view'] = (isset ($_GET['view'])) ? htmlentities($_GET['view']) : 'index';
$_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id';
$id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : '';
$url = (isset ($_GET['url'])) ? $_GET['url'] : '';
$token = (isset ($_REQUEST['token'])) ? $_REQUEST['token'] : '';
if ($action != '') {
action_to_do($action, $id, $url, $token);
}

View File

@ -146,6 +146,20 @@ function action_to_do($action, $id, $url, $token)
} }
else die('CSRF problem'); else die('CSRF problem');
break; break;
case 'toggle_fav' :
if (verif_token($token)) {
$sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?";
$params_action = array($id);
}
else die('CSRF problem');
break;
case 'toggle_archive' :
if (verif_token($token)) {
$sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?";
$params_action = array($id);
}
else die('CSRF problem');
break;
default: default:
break; break;
} }
@ -168,22 +182,41 @@ function action_to_do($action, $id, $url, $token)
/** /**
* Détermine quels liens afficher : home, fav ou archives * Détermine quels liens afficher : home, fav ou archives
*/ */
function display_view($view) function display_view()
{ {
global $db; global $db;
switch ($view) 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 ($_SESSION['view'])
{ {
case 'archive': case 'archive':
$sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; $sql = "SELECT * FROM entries WHERE is_read=? " . $order;
$params = array(-1); $params = array(-1);
break; break;
case 'fav' : case 'fav' :
$sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc"; $sql = "SELECT * FROM entries WHERE is_fav=? " . $order;
$params = array(-1); $params = array(-1);
break; break;
default: default:
$sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; $sql = "SELECT * FROM entries WHERE is_read=? " . $order;
$params = array(0); $params = array(0);
break; break;
} }

View File

@ -10,22 +10,17 @@
include dirname(__FILE__).'/inc/config.php'; include dirname(__FILE__).'/inc/config.php';
$action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : ''; $entries = display_view();
$view = (isset ($_GET['view'])) ? htmlentities($_GET['view']) : 'index';
$id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : '';
$url = (isset ($_GET['url'])) ? $_GET['url'] : '';
$token = (isset ($_POST['token'])) ? $_POST['token'] : '';
if ($action != '') {
action_to_do($action, $id, $url, $token);
}
$entries = display_view($view);
$tpl->assign('title', 'poche, a read it later open source system'); $tpl->assign('title', 'poche, a read it later open source system');
$tpl->assign('view', $view); $tpl->assign('view', $_SESSION['view']);
$tpl->assign('poche_url', get_poche_url()); $tpl->assign('poche_url', get_poche_url());
$tpl->assign('entries', $entries); $tpl->assign('entries', $entries);
$tpl->assign('load_all_js', 1); $tpl->assign('load_all_js', 1);
$tpl->assign('token', $_SESSION['token_poche']); $tpl->assign('token', $_SESSION['token_poche']);
$tpl->draw('head');
$tpl->draw('home'); $tpl->draw('home');
$tpl->draw('entries');
$tpl->draw('js');
$tpl->draw('footer');

View File

@ -1,7 +1,7 @@
function toggle_favorite(element, id, token) { function toggle_favorite(element, id, token) {
$(element).toggleClass('fav-off'); $(element).toggleClass('fav-off');
$.ajax ({ $.ajax ({
url: "process.php?action=toggle_fav", url: "index.php?action=toggle_fav",
data:{id:id, token:token} data:{id:id, token:token}
}); });
} }
@ -9,7 +9,7 @@ function toggle_favorite(element, id, token) {
function toggle_archive(element, id, token, view_article) { function toggle_archive(element, id, token, view_article) {
$(element).toggleClass('archive-off'); $(element).toggleClass('archive-off');
$.ajax ({ $.ajax ({
url: "process.php?action=toggle_archive", url: "index.php?action=toggle_archive",
data:{id:id, token:token} data:{id:id, token:token}
}); });
var obj = $('#entry-'+id); var obj = $('#entry-'+id);
@ -21,3 +21,7 @@ function toggle_archive(element, id, token, view_article) {
$('#content').masonry('reload'); $('#content').masonry('reload');
} }
} }
function sort_links(sort, token) {
$('#content').load('process.php', { sort: sort, token: token } );
}

View File

@ -1,40 +0,0 @@
<?php
/**
* poche, a read it later open source system
*
* @category poche
* @author Nicolas Lœuillet <nicolas@loeuillet.org>
* @copyright 2013
* @license http://www.wtfpl.net/ see COPYING file
*/
include dirname(__FILE__).'/inc/config.php';
$db = new db(DB_PATH);
$action = (isset ($_GET['action'])) ? htmlentities($_GET['action']) : '';
$id = (isset ($_GET['id'])) ? htmlentities($_GET['id']) : '';
$token = (isset ($_GET['token'])) ? $_GET['token'] : '';
if (verif_token($token)) {
switch ($action)
{
case 'toggle_fav' :
$sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?";
$params_action = array($id);
break;
case 'toggle_archive' :
$sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?";
$params_action = array($id);
break;
default:
break;
}
# action query
if (isset($sql_action))
{
$query = $db->getHandle()->prepare($sql_action);
$query->execute($params_action);
}
}
else die('CSRF problem');

16
tpl/entries.html Normal file
View File

@ -0,0 +1,16 @@
{loop="entries"}
<div id="entry-{$value.id}" class="entrie mb2">
<span class="content">
<h2 class="h6-like">
<a href="view.php?id={$value.id}">{$value.title}</a>
</h2>
<div class="tools">
<ul>
<li><a title="toggle mark as read" class="tool archive {if="$value.is_read == '0'"}archive-off{/if}" onclick="toggle_archive(this, {$value.id}, '{$token}')"><span></span></a></li>
<li><a title="toggle favorite" class="tool fav {if="$value.is_fav == '0'"}fav-off{/if}" onclick="toggle_favorite(this, {$value.id}, '{$token}')"><span></span></a></li>
<li><form method="post" onsubmit="return confirm('Are you sure?')" style="display: inline;"><input type="hidden" name="token" id="token" value="{$token}" /><input type="hidden" id="action" name="action" value="delete" /><input type="hidden" id="id" name="id" value="{$value.id}" /><input type="submit" class="delete" title="toggle delete" /></form></li>
</ul>
</div>
</span>
</div>
{/loop}

View File

@ -1,3 +1,9 @@
</div>
</div>
<footer class="mr2 mt3 smaller"> <footer class="mr2 mt3 smaller">
<p>powered by <a href="http://inthepoche.com">poche</a><br />follow us on <a href="https://twitter.com/getpoche" title="follow us on twitter">twitter</a></p> <p>powered by <a href="http://inthepoche.com">poche</a><br />follow us on <a href="https://twitter.com/getpoche" title="follow us on twitter">twitter</a></p>
</footer> </footer>
</body>
</html>

View File

@ -1,4 +1,3 @@
{include="head"}
<body> <body>
<header> <header>
<h1><img src="./img/logo.png" alt="logo poche" />poche</h1> <h1><img src="./img/logo.png" alt="logo poche" />poche</h1>
@ -10,26 +9,10 @@
<li><a href="?view=archive" {if="$view == 'archive'"}class="current"{/if}>archive</a></li> <li><a href="?view=archive" {if="$view == 'archive'"}class="current"{/if}>archive</a></li>
<li><a style="cursor: move" title="i am a bookmarklet, use me !" href="javascript:(function(){var%20url%20=%20location.href%20||%20url;window.open('{$poche_url}?action=add&url='%20+%20encodeURIComponent(url),'_self');})();">poche it !</a></li> <li><a style="cursor: move" title="i am a bookmarklet, use me !" href="javascript:(function(){var%20url%20=%20location.href%20||%20url;window.open('{$poche_url}?action=add&url='%20+%20encodeURIComponent(url),'_self');})();">poche it !</a></li>
</ul> </ul>
<!-- <ul>
<li onclick="sort_links('ia', '{$token}');">tri par id asc</li>
<li onclick="sort_links('id', '{$token}');">tri par id desc</li>
<li onclick="sort_links('ta', '{$token}');">tri par title asc</li>
<li onclick="sort_links('td', '{$token}');">tri par title desc</li>
</ul> -->
<div id="content"> <div id="content">
{loop="entries"}
<div id="entry-{$value.id}" class="entrie mb2">
<span class="content">
<h2 class="h6-like">
<a href="view.php?id={$value.id}">{$value.title}</a>
</h2>
<div class="tools">
<ul>
<li><a title="toggle mark as read" class="tool archive {if="$value.is_read == '0'"}archive-off{/if}" onclick="toggle_archive(this, {$value.id}, '{$token}')"><span></span></a></li>
<li><a title="toggle favorite" class="tool fav {if="$value.is_fav == '0'"}fav-off{/if}" onclick="toggle_favorite(this, {$value.id}, '{$token}')"><span></span></a></li>
<li><form method="post" onsubmit="return confirm('Are you sure?')" style="display: inline;"><input type="hidden" name="token" id="token" value="{$token}" /><input type="hidden" id="action" name="action" value="delete" /><input type="hidden" id="id" name="id" value="{$value.id}" /><input type="submit" class="delete" title="toggle delete" /></form></li>
</ul>
</div>
</span>
</div>
{/loop}
</div>
</div>
{include="footer"}
{include="js"}
</body>
</html>