1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-12-17 13:12:15 -05:00

tout est recentré sur index.php

This commit is contained in:
nicosomb 2013-04-19 11:41:12 +02:00
parent c00cdfdd3b
commit a1953dff8f
11 changed files with 123 additions and 134 deletions

View File

@ -93,7 +93,7 @@ class Session
// Force logout // Force logout
public static function logout() public static function logout()
{ {
unset($_SESSION['uid'],$_SESSION['info'],$_SESSION['expires_on']); unset($_SESSION['uid'],$_SESSION['info'],$_SESSION['expires_on'],$_SESSION['tokens']);
} }
// Make sure user is logged in. // Make sure user is logged in.

View File

@ -34,58 +34,3 @@ raintpl::$base_url = get_poche_url();
raintpl::configure('path_replace', false); raintpl::configure('path_replace', false);
raintpl::configure('debug', false); raintpl::configure('debug', false);
$tpl = new raintpl(); $tpl = new raintpl();
# initialize session
Session::init();
# XSRF protection with token
if (!empty($_POST)) {
if (!Session::isToken($_POST['token'])) {
die('Wrong token.');
}
unset($_SESSION['tokens']);
}
$ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
if (isset($_GET['login'])) {
// Login
if (!empty($_POST['login']) && !empty($_POST['password'])) {
if (Session::login('poche', 'poche', $_POST['login'], $_POST['password'])) {
if (!empty($_POST['longlastingsession'])) {
$_SESSION['longlastingsession'] = 31536000;
$_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
session_set_cookie_params($_SESSION['longlastingsession']);
} else {
session_set_cookie_params(0); // when browser closes
}
session_regenerate_id(true);
MyTool::redirect();
}
logm('login failed');
die("Login failed !");
} else {
logm('login successful');
}
}
elseif (isset($_GET['logout'])) {
logm('logout');
Session::logout();
MyTool::redirect();
}
# Traitement des paramètres et déclenchement des actions
$view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index';
$action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : '';
$_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id';
$id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : '';
$url = (isset ($_GET['url'])) ? $_GET['url'] : '';
$tpl->assign('isLogged', Session::isLogged());
$tpl->assign('referer', $ref);
$tpl->assign('view', $view);
$tpl->assign('poche_url', get_poche_url());
if ($action != '') {
action_to_do($action, $url, $id);
}

View File

@ -226,10 +226,55 @@ function remove_directory($directory)
} }
} }
function display_view($view, $id = 0, $full_head = 'yes')
{
global $tpl;
switch ($view)
{
case 'view':
$entry = get_article($id);
if ($entry != NULL) {
$tpl->assign('id', $entry[0]['id']);
$tpl->assign('url', $entry[0]['url']);
$tpl->assign('title', $entry[0]['title']);
$tpl->assign('content', $entry[0]['content']);
$tpl->assign('is_fav', $entry[0]['is_fav']);
$tpl->assign('is_read', $entry[0]['is_read']);
$tpl->assign('load_all_js', 0);
$tpl->draw('view');
}
else {
logm('error in view call : entry is NULL');
}
logm('view link #' . $id);
break;
default: # home view
$entries = get_entries($view);
$tpl->assign('entries', $entries);
if ($full_head == 'yes') {
$tpl->assign('load_all_js', 1);
$tpl->draw('head');
$tpl->draw('home');
}
$tpl->draw('entries');
if ($full_head == 'yes') {
$tpl->draw('js');
$tpl->draw('footer');
}
break;
}
}
/** /**
* Appel d'une action (mark as fav, archive, delete) * Appel d'une action (mark as fav, archive, delete)
*/ */
function action_to_do($action, $url, $id = 0) function action_to_do($action, $url, $id = 0)
{ {
global $db; global $db;

View File

@ -10,19 +10,63 @@
include dirname(__FILE__).'/inc/config.php'; include dirname(__FILE__).'/inc/config.php';
$entries = get_entries($view); # initialize session
Session::init();
# XSRF protection with token
if (!empty($_POST)) {
if (!Session::isToken($_POST['token'])) {
die('Wrong token.');
}
unset($_SESSION['tokens']);
}
if (isset($_GET['login'])) {
// Login
if (!empty($_POST['login']) && !empty($_POST['password'])) {
if (Session::login('poche', 'poche', $_POST['login'], $_POST['password'])) {
logm('login successful');
if (!empty($_POST['longlastingsession'])) {
$_SESSION['longlastingsession'] = 31536000;
$_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
session_set_cookie_params($_SESSION['longlastingsession']);
} else {
session_set_cookie_params(0); // when browser closes
}
session_regenerate_id(true);
MyTool::redirect();
}
logm('login failed');
die("Login failed !");
} else {
logm('login failed');
}
}
elseif (isset($_GET['logout'])) {
logm('logout');
Session::logout();
MyTool::redirect();
}
# Traitement des paramètres et déclenchement des actions
$view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index';
$full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes';
$action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : '';
$_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id';
$id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : '';
$url = (isset ($_GET['url'])) ? $_GET['url'] : '';
$ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
$tpl->assign('isLogged', Session::isLogged());
$tpl->assign('referer', $ref);
$tpl->assign('view', $view);
$tpl->assign('poche_url', get_poche_url());
$tpl->assign('title', 'poche, a read it later open source system'); $tpl->assign('title', 'poche, a read it later open source system');
$tpl->assign('entries', $entries);
$tpl->assign('load_all_js', 1);
$tpl->draw('head');
if (Session::isLogged()) { if (Session::isLogged()) {
$tpl->draw('home'); action_to_do($action, $url, $id);
$tpl->draw('entries'); display_view($view, $id, $full_head);
$tpl->draw('js');
} }
else { else {
$tpl->draw('login'); $tpl->draw('login');
} }
$tpl->draw('footer');

View File

@ -1,16 +1,16 @@
function toggle_favorite(element, id, token) { function toggle_favorite(element, id) {
$(element).toggleClass('fav-off'); $(element).toggleClass('fav-off');
$.ajax ({ $.ajax ({
url: "index.php?action=toggle_fav", url: "index.php?action=toggle_fav",
data:{id:id, token:token} data:{id:id}
}); });
} }
function toggle_archive(element, id, token, view_article) { function toggle_archive(element, id, view_article) {
$(element).toggleClass('archive-off'); $(element).toggleClass('archive-off');
$.ajax ({ $.ajax ({
url: "index.php?action=toggle_archive", url: "index.php?action=toggle_archive",
data:{id:id, token:token} data:{id:id}
}); });
var obj = $('#entry-'+id); var obj = $('#entry-'+id);
@ -22,6 +22,9 @@ function toggle_archive(element, id, token, view_article) {
} }
} }
function sort_links(view, sort, token) { function sort_links(view, sort) {
$('#content').load('process.php', { view: view, sort: sort, token: token } ); //$('#content').load('index.php', { view: view, sort: sort, full_head: 'no' } );
$.get('index.php', { view: view, sort: sort, full_head: 'no' }, function(data) {
$('#content').html(data);
});
} }

View File

@ -1,16 +0,0 @@
<?php
/**
* poche, a read it later open source system
*
* @category poche
* @author Nicolas Lœuillet <support@inthepoche.com>
* @copyright 2013
* @license http://www.wtfpl.net/ see COPYING file
*/
include dirname(__FILE__).'/inc/config.php';
$entries = display_view($view);
$tpl->assign('token', $_SESSION['token_poche']);
$tpl->assign('entries', $entries);
$tpl->draw('entries');

View File

@ -2,13 +2,13 @@
<div id="entry-{$value.id}" class="entrie mb2"> <div id="entry-{$value.id}" class="entrie mb2">
<span class="content"> <span class="content">
<h2 class="h6-like"> <h2 class="h6-like">
<a href="view.php?id={$value.id}">{$value.title}</a> <a href="index.php?&view=view&id={$value.id}">{$value.title}</a>
</h2> </h2>
<div class="tools"> <div class="tools">
<ul> <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}, '<?php echo Session::getToken(); ?>')"><span></span></a></li> <li><a title="toggle mark as read" class="tool archive {if="$value.is_read == '0'"}archive-off{/if}" onclick="toggle_archive(this, {$value.id})"><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}, '<?php echo Session::getToken(); ?>')"><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})"><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="<?php echo Session::getToken(); ?>" /><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> <li><form method="post" onsubmit="return confirm('Are you sure?')" style="display: inline;"><input type="hidden" name="token" id="token" value="<?php echo Session::getToken(); ?>" /><input type="hidden" id="action" name="action" value="delete" /><input type="hidden" id="view" name="view" value="{$view}" /><input type="hidden" id="id" name="id" value="{$value.id}" /><input type="submit" class="delete" title="toggle delete" /></form></li>
</ul> </ul>
</div> </div>
</span> </span>

View File

@ -6,7 +6,7 @@
<li><a href="?logout" title="Logout">logout</a></li> <li><a href="?logout" title="Logout">logout</a></li>
</ul> </ul>
<ul id="sort"> <ul id="sort">
<li><img src="img/up.png" onclick="sort_links('{$view}', 'ia', '{'<?php echo Session::getToken(); ?>'}');" title="by date asc" /> by date <img src="img/down.png" onclick="sort_links('{$view}', 'id', '<?php echo Session::getToken(); ?>');" title="by date desc" /></li> <li><img src="img/up.png" onclick="sort_links('{$view}', 'ia');" title="by date asc" /> by date <img src="img/down.png" onclick="sort_links('{$view}', 'id');" title="by date desc" /></li>
<li><img src="img/up.png" onclick="sort_links('{$view}', 'ta', '<?php echo Session::getToken(); ?>');" title="by title asc" /> by title <img src="img/down.png" onclick="sort_links('{$view}', 'td', '<?php echo Session::getToken(); ?>');" title="by title desc" /></li> <li><img src="img/up.png" onclick="sort_links('{$view}', 'ta');" title="by title asc" /> by title <img src="img/down.png" onclick="sort_links('{$view}', 'td');" title="by title desc" /></li>
</ul> </ul>
<div id="content"> <div id="content">

View File

@ -1,3 +1,4 @@
{include="head"}
<form method="post" action="?login" name="loginform"> <form method="post" action="?login" name="loginform">
<fieldset> <fieldset>
<h2>login to your poche</h2> <h2>login to your poche</h2>
@ -19,3 +20,4 @@
<input type="hidden" name="returnurl" value="<?php echo htmlspecialchars($referer);?>"> <input type="hidden" name="returnurl" value="<?php echo htmlspecialchars($referer);?>">
<input type="hidden" name="token" value="<?php echo Session::getToken(); ?>"> <input type="hidden" name="token" value="<?php echo Session::getToken(); ?>">
</form> </form>
{include="footer"}

View File

@ -23,9 +23,10 @@
</div> </div>
<div class="tools"> <div class="tools">
<ul> <ul>
<li><a title="toggle mark as read" class="tool archive {if="$is_read == '0'"}archive-off{/if}" onclick="toggle_archive(this, {$id}, '<?php echo Session::getToken(); ?>')"><span></span></a></li> <li><a title="toggle mark as read" class="tool archive {if="$is_read == '0'"}archive-off{/if}" onclick="toggle_archive(this, {$id})"><span></span></a></li>
<li><a title="toggle favorite" class="tool fav {if="$is_fav == '0'"}fav-off{/if}" onclick="toggle_favorite(this, {$id}, '<?php echo Session::getToken(); ?>')"><span></span></a></li> <li><a title="toggle favorite" class="tool fav {if="$is_fav == '0'"}fav-off{/if}" onclick="toggle_favorite(this, {$id})"><span></span></a></li>
<li><form method="post" onsubmit="return confirm('Are you sure?')" style="display: inline;" action="index.php"><input type="hidden" name="token" id="token" value="<?php echo Session::getToken(); ?>" /><input type="hidden" id="action" name="action" value="delete" /><input type="hidden" id="id" name="id" value="{$id}" /><input type="submit" class="delete" title="toggle delete" /></form></li> <li><form method="post" onsubmit="return confirm('Are you sure?')" style="display: inline;" action="index.php"><input type="hidden" name="token" id="token" value="<?php echo Session::getToken(); ?>" /><input type="hidden" id="view" name="view" value="index" /><input type="hidden" id="action" name="action" value="delete" /><input type="hidden" id="id" name="id" value="{$id}" /><input type="submit" class="delete" title="toggle delete" /></form></li>
<li><a href="?logout" title="Logout">logout</a></li>
</ul> </ul>
</div> </div>
<header class="mbm"> <header class="mbm">

View File

@ -1,35 +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';
$id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : '';
if(!empty($id)) {
$entry = get_article($id);
if ($entry != NULL) {
$tpl->assign('id', $entry[0]['id']);
$tpl->assign('url', $entry[0]['url']);
$tpl->assign('title', $entry[0]['title']);
$tpl->assign('content', $entry[0]['content']);
$tpl->assign('is_fav', $entry[0]['is_fav']);
$tpl->assign('is_read', $entry[0]['is_read']);
$tpl->assign('load_all_js', 0);
$tpl->draw('view');
}
else {
logm('error in view call : entry is NULL');
}
}
else {
logm('error in view call : id is empty');
}