diff options
author | nicosomb <nicolas@loeuillet.org> | 2013-04-19 11:41:12 +0200 |
---|---|---|
committer | nicosomb <nicolas@loeuillet.org> | 2013-04-19 11:41:12 +0200 |
commit | a1953dff8f39b225b408c3046246e9446a01f305 (patch) | |
tree | 70b1989080f5fcf9581dc6aa208664efaeb7b02d | |
parent | c00cdfdd3bc8e53750d34c60d13cd2d885c5d4fd (diff) | |
download | wallabag-a1953dff8f39b225b408c3046246e9446a01f305.tar.gz wallabag-a1953dff8f39b225b408c3046246e9446a01f305.tar.zst wallabag-a1953dff8f39b225b408c3046246e9446a01f305.zip |
tout est recentré sur index.php0.1
-rw-r--r-- | inc/Session.class.php | 2 | ||||
-rw-r--r-- | inc/config.php | 57 | ||||
-rw-r--r-- | inc/functions.php | 47 | ||||
-rw-r--r-- | index.php | 62 | ||||
-rw-r--r-- | js/poche.js | 15 | ||||
-rw-r--r-- | process.php | 16 | ||||
-rw-r--r-- | tpl/entries.html | 8 | ||||
-rw-r--r-- | tpl/home.html | 4 | ||||
-rw-r--r-- | tpl/login.html | 4 | ||||
-rw-r--r-- | tpl/view.html | 7 | ||||
-rw-r--r-- | view.php | 35 |
11 files changed, 123 insertions, 134 deletions
diff --git a/inc/Session.class.php b/inc/Session.class.php index 06fa6a8e..ee12b3d1 100644 --- a/inc/Session.class.php +++ b/inc/Session.class.php | |||
@@ -93,7 +93,7 @@ class Session | |||
93 | // Force logout | 93 | // Force logout |
94 | public static function logout() | 94 | public static function logout() |
95 | { | 95 | { |
96 | unset($_SESSION['uid'],$_SESSION['info'],$_SESSION['expires_on']); | 96 | unset($_SESSION['uid'],$_SESSION['info'],$_SESSION['expires_on'],$_SESSION['tokens']); |
97 | } | 97 | } |
98 | 98 | ||
99 | // Make sure user is logged in. | 99 | // Make sure user is logged in. |
diff --git a/inc/config.php b/inc/config.php index 403217ce..063952a5 100644 --- a/inc/config.php +++ b/inc/config.php | |||
@@ -33,59 +33,4 @@ raintpl::$cache_dir = './cache/'; | |||
33 | raintpl::$base_url = get_poche_url(); | 33 | raintpl::$base_url = get_poche_url(); |
34 | raintpl::configure('path_replace', false); | 34 | raintpl::configure('path_replace', false); |
35 | raintpl::configure('debug', false); | 35 | raintpl::configure('debug', false); |
36 | $tpl = new raintpl(); | 36 | $tpl = new raintpl(); \ No newline at end of file |
37 | |||
38 | # initialize session | ||
39 | Session::init(); | ||
40 | # XSRF protection with token | ||
41 | if (!empty($_POST)) { | ||
42 | if (!Session::isToken($_POST['token'])) { | ||
43 | die('Wrong token.'); | ||
44 | } | ||
45 | unset($_SESSION['tokens']); | ||
46 | } | ||
47 | |||
48 | $ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; | ||
49 | |||
50 | if (isset($_GET['login'])) { | ||
51 | // Login | ||
52 | if (!empty($_POST['login']) && !empty($_POST['password'])) { | ||
53 | if (Session::login('poche', 'poche', $_POST['login'], $_POST['password'])) { | ||
54 | if (!empty($_POST['longlastingsession'])) { | ||
55 | $_SESSION['longlastingsession'] = 31536000; | ||
56 | $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; | ||
57 | session_set_cookie_params($_SESSION['longlastingsession']); | ||
58 | } else { | ||
59 | session_set_cookie_params(0); // when browser closes | ||
60 | } | ||
61 | session_regenerate_id(true); | ||
62 | |||
63 | MyTool::redirect(); | ||
64 | } | ||
65 | logm('login failed'); | ||
66 | die("Login failed !"); | ||
67 | } else { | ||
68 | logm('login successful'); | ||
69 | } | ||
70 | } | ||
71 | elseif (isset($_GET['logout'])) { | ||
72 | logm('logout'); | ||
73 | Session::logout(); | ||
74 | MyTool::redirect(); | ||
75 | } | ||
76 | |||
77 | # Traitement des paramètres et déclenchement des actions | ||
78 | $view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index'; | ||
79 | $action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : ''; | ||
80 | $_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id'; | ||
81 | $id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : ''; | ||
82 | $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; | ||
83 | |||
84 | $tpl->assign('isLogged', Session::isLogged()); | ||
85 | $tpl->assign('referer', $ref); | ||
86 | $tpl->assign('view', $view); | ||
87 | $tpl->assign('poche_url', get_poche_url()); | ||
88 | |||
89 | if ($action != '') { | ||
90 | action_to_do($action, $url, $id); | ||
91 | } | ||
diff --git a/inc/functions.php b/inc/functions.php index 13acd36f..ef1fc0e2 100644 --- a/inc/functions.php +++ b/inc/functions.php | |||
@@ -226,10 +226,55 @@ function remove_directory($directory) | |||
226 | } | 226 | } |
227 | } | 227 | } |
228 | 228 | ||
229 | function display_view($view, $id = 0, $full_head = 'yes') | ||
230 | { | ||
231 | global $tpl; | ||
232 | |||
233 | switch ($view) | ||
234 | { | ||
235 | case 'view': | ||
236 | $entry = get_article($id); | ||
237 | |||
238 | if ($entry != NULL) { | ||
239 | $tpl->assign('id', $entry[0]['id']); | ||
240 | $tpl->assign('url', $entry[0]['url']); | ||
241 | $tpl->assign('title', $entry[0]['title']); | ||
242 | $tpl->assign('content', $entry[0]['content']); | ||
243 | $tpl->assign('is_fav', $entry[0]['is_fav']); | ||
244 | $tpl->assign('is_read', $entry[0]['is_read']); | ||
245 | $tpl->assign('load_all_js', 0); | ||
246 | $tpl->draw('view'); | ||
247 | } | ||
248 | else { | ||
249 | logm('error in view call : entry is NULL'); | ||
250 | } | ||
251 | |||
252 | logm('view link #' . $id); | ||
253 | break; | ||
254 | default: # home view | ||
255 | $entries = get_entries($view); | ||
256 | |||
257 | $tpl->assign('entries', $entries); | ||
258 | |||
259 | if ($full_head == 'yes') { | ||
260 | $tpl->assign('load_all_js', 1); | ||
261 | $tpl->draw('head'); | ||
262 | $tpl->draw('home'); | ||
263 | } | ||
264 | |||
265 | $tpl->draw('entries'); | ||
266 | |||
267 | if ($full_head == 'yes') { | ||
268 | $tpl->draw('js'); | ||
269 | $tpl->draw('footer'); | ||
270 | } | ||
271 | break; | ||
272 | } | ||
273 | } | ||
274 | |||
229 | /** | 275 | /** |
230 | * Appel d'une action (mark as fav, archive, delete) | 276 | * Appel d'une action (mark as fav, archive, delete) |
231 | */ | 277 | */ |
232 | |||
233 | function action_to_do($action, $url, $id = 0) | 278 | function action_to_do($action, $url, $id = 0) |
234 | { | 279 | { |
235 | global $db; | 280 | global $db; |
@@ -10,19 +10,63 @@ | |||
10 | 10 | ||
11 | include dirname(__FILE__).'/inc/config.php'; | 11 | include dirname(__FILE__).'/inc/config.php'; |
12 | 12 | ||
13 | $entries = get_entries($view); | 13 | # initialize session |
14 | Session::init(); | ||
15 | # XSRF protection with token | ||
16 | if (!empty($_POST)) { | ||
17 | if (!Session::isToken($_POST['token'])) { | ||
18 | die('Wrong token.'); | ||
19 | } | ||
20 | unset($_SESSION['tokens']); | ||
21 | } | ||
22 | |||
23 | if (isset($_GET['login'])) { | ||
24 | // Login | ||
25 | if (!empty($_POST['login']) && !empty($_POST['password'])) { | ||
26 | if (Session::login('poche', 'poche', $_POST['login'], $_POST['password'])) { | ||
27 | logm('login successful'); | ||
28 | if (!empty($_POST['longlastingsession'])) { | ||
29 | $_SESSION['longlastingsession'] = 31536000; | ||
30 | $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; | ||
31 | session_set_cookie_params($_SESSION['longlastingsession']); | ||
32 | } else { | ||
33 | session_set_cookie_params(0); // when browser closes | ||
34 | } | ||
35 | session_regenerate_id(true); | ||
14 | 36 | ||
37 | MyTool::redirect(); | ||
38 | } | ||
39 | logm('login failed'); | ||
40 | die("Login failed !"); | ||
41 | } else { | ||
42 | logm('login failed'); | ||
43 | } | ||
44 | } | ||
45 | elseif (isset($_GET['logout'])) { | ||
46 | logm('logout'); | ||
47 | Session::logout(); | ||
48 | MyTool::redirect(); | ||
49 | } | ||
50 | |||
51 | # Traitement des paramètres et déclenchement des actions | ||
52 | $view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index'; | ||
53 | $full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes'; | ||
54 | $action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : ''; | ||
55 | $_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id'; | ||
56 | $id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : ''; | ||
57 | $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; | ||
58 | $ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; | ||
59 | |||
60 | $tpl->assign('isLogged', Session::isLogged()); | ||
61 | $tpl->assign('referer', $ref); | ||
62 | $tpl->assign('view', $view); | ||
63 | $tpl->assign('poche_url', get_poche_url()); | ||
15 | $tpl->assign('title', 'poche, a read it later open source system'); | 64 | $tpl->assign('title', 'poche, a read it later open source system'); |
16 | $tpl->assign('entries', $entries); | ||
17 | $tpl->assign('load_all_js', 1); | ||
18 | 65 | ||
19 | $tpl->draw('head'); | ||
20 | if (Session::isLogged()) { | 66 | if (Session::isLogged()) { |
21 | $tpl->draw('home'); | 67 | action_to_do($action, $url, $id); |
22 | $tpl->draw('entries'); | 68 | display_view($view, $id, $full_head); |
23 | $tpl->draw('js'); | ||
24 | } | 69 | } |
25 | else { | 70 | else { |
26 | $tpl->draw('login'); | 71 | $tpl->draw('login'); |
27 | } | 72 | } \ No newline at end of file |
28 | $tpl->draw('footer'); \ No newline at end of file | ||
diff --git a/js/poche.js b/js/poche.js index 98fc48ea..6bc3c188 100644 --- a/js/poche.js +++ b/js/poche.js | |||
@@ -1,16 +1,16 @@ | |||
1 | function toggle_favorite(element, id, token) { | 1 | function toggle_favorite(element, id) { |
2 | $(element).toggleClass('fav-off'); | 2 | $(element).toggleClass('fav-off'); |
3 | $.ajax ({ | 3 | $.ajax ({ |
4 | url: "index.php?action=toggle_fav", | 4 | url: "index.php?action=toggle_fav", |
5 | data:{id:id, token:token} | 5 | data:{id:id} |
6 | }); | 6 | }); |
7 | } | 7 | } |
8 | 8 | ||
9 | function toggle_archive(element, id, token, view_article) { | 9 | function toggle_archive(element, id, view_article) { |
10 | $(element).toggleClass('archive-off'); | 10 | $(element).toggleClass('archive-off'); |
11 | $.ajax ({ | 11 | $.ajax ({ |
12 | url: "index.php?action=toggle_archive", | 12 | url: "index.php?action=toggle_archive", |
13 | data:{id:id, token:token} | 13 | data:{id:id} |
14 | }); | 14 | }); |
15 | var obj = $('#entry-'+id); | 15 | var obj = $('#entry-'+id); |
16 | 16 | ||
@@ -22,6 +22,9 @@ function toggle_archive(element, id, token, view_article) { | |||
22 | } | 22 | } |
23 | } | 23 | } |
24 | 24 | ||
25 | function sort_links(view, sort, token) { | 25 | function sort_links(view, sort) { |
26 | $('#content').load('process.php', { view: view, sort: sort, token: token } ); | 26 | //$('#content').load('index.php', { view: view, sort: sort, full_head: 'no' } ); |
27 | $.get('index.php', { view: view, sort: sort, full_head: 'no' }, function(data) { | ||
28 | $('#content').html(data); | ||
29 | }); | ||
27 | } \ No newline at end of file | 30 | } \ No newline at end of file |
diff --git a/process.php b/process.php deleted file mode 100644 index 14686885..00000000 --- a/process.php +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * poche, a read it later open source system | ||
4 | * | ||
5 | * @category poche | ||
6 | * @author Nicolas Lœuillet <support@inthepoche.com> | ||
7 | * @copyright 2013 | ||
8 | * @license http://www.wtfpl.net/ see COPYING file | ||
9 | */ | ||
10 | |||
11 | include dirname(__FILE__).'/inc/config.php'; | ||
12 | |||
13 | $entries = display_view($view); | ||
14 | $tpl->assign('token', $_SESSION['token_poche']); | ||
15 | $tpl->assign('entries', $entries); | ||
16 | $tpl->draw('entries'); \ No newline at end of file | ||
diff --git a/tpl/entries.html b/tpl/entries.html index c74bc346..648e1ce9 100644 --- a/tpl/entries.html +++ b/tpl/entries.html | |||
@@ -2,13 +2,13 @@ | |||
2 | <div id="entry-{$value.id}" class="entrie mb2"> | 2 | <div id="entry-{$value.id}" class="entrie mb2"> |
3 | <span class="content"> | 3 | <span class="content"> |
4 | <h2 class="h6-like"> | 4 | <h2 class="h6-like"> |
5 | <a href="view.php?id={$value.id}">{$value.title}</a> | 5 | <a href="index.php?&view=view&id={$value.id}">{$value.title}</a> |
6 | </h2> | 6 | </h2> |
7 | <div class="tools"> | 7 | <div class="tools"> |
8 | <ul> | 8 | <ul> |
9 | <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> | 9 | <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> |
10 | <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> | 10 | <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> |
11 | <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> | 11 | <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> |
12 | </ul> | 12 | </ul> |
13 | </div> | 13 | </div> |
14 | </span> | 14 | </span> |
diff --git a/tpl/home.html b/tpl/home.html index 216f39b9..6fb9444c 100644 --- a/tpl/home.html +++ b/tpl/home.html | |||
@@ -6,7 +6,7 @@ | |||
6 | <li><a href="?logout" title="Logout">logout</a></li> | 6 | <li><a href="?logout" title="Logout">logout</a></li> |
7 | </ul> | 7 | </ul> |
8 | <ul id="sort"> | 8 | <ul id="sort"> |
9 | <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> | 9 | <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> |
10 | <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> | 10 | <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> |
11 | </ul> | 11 | </ul> |
12 | <div id="content"> \ No newline at end of file | 12 | <div id="content"> \ No newline at end of file |
diff --git a/tpl/login.html b/tpl/login.html index bf0f4fa6..d3139ab3 100644 --- a/tpl/login.html +++ b/tpl/login.html | |||
@@ -1,3 +1,4 @@ | |||
1 | {include="head"} | ||
1 | <form method="post" action="?login" name="loginform"> | 2 | <form method="post" action="?login" name="loginform"> |
2 | <fieldset> | 3 | <fieldset> |
3 | <h2>login to your poche</h2> | 4 | <h2>login to your poche</h2> |
@@ -18,4 +19,5 @@ | |||
18 | </fieldset> | 19 | </fieldset> |
19 | <input type="hidden" name="returnurl" value="<?php echo htmlspecialchars($referer);?>"> | 20 | <input type="hidden" name="returnurl" value="<?php echo htmlspecialchars($referer);?>"> |
20 | <input type="hidden" name="token" value="<?php echo Session::getToken(); ?>"> | 21 | <input type="hidden" name="token" value="<?php echo Session::getToken(); ?>"> |
21 | </form> \ No newline at end of file | 22 | </form> |
23 | {include="footer"} \ No newline at end of file | ||
diff --git a/tpl/view.html b/tpl/view.html index 1191bd82..4b8ce60f 100644 --- a/tpl/view.html +++ b/tpl/view.html | |||
@@ -23,9 +23,10 @@ | |||
23 | </div> | 23 | </div> |
24 | <div class="tools"> | 24 | <div class="tools"> |
25 | <ul> | 25 | <ul> |
26 | <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> | 26 | <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> |
27 | <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> | 27 | <li><a title="toggle favorite" class="tool fav {if="$is_fav == '0'"}fav-off{/if}" onclick="toggle_favorite(this, {$id})"><span></span></a></li> |
28 | <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> | 28 | <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> |
29 | <li><a href="?logout" title="Logout">logout</a></li> | ||
29 | </ul> | 30 | </ul> |
30 | </div> | 31 | </div> |
31 | <header class="mbm"> | 32 | <header class="mbm"> |
diff --git a/view.php b/view.php deleted file mode 100644 index 29a5b324..00000000 --- a/view.php +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * poche, a read it later open source system | ||
4 | * | ||
5 | * @category poche | ||
6 | * @author Nicolas Lœuillet <nicolas@loeuillet.org> | ||
7 | * @copyright 2013 | ||
8 | * @license http://www.wtfpl.net/ see COPYING file | ||
9 | */ | ||
10 | |||
11 | include dirname(__FILE__).'/inc/config.php'; | ||
12 | |||
13 | $id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; | ||
14 | |||
15 | if(!empty($id)) { | ||
16 | |||
17 | $entry = get_article($id); | ||
18 | |||
19 | if ($entry != NULL) { | ||
20 | $tpl->assign('id', $entry[0]['id']); | ||
21 | $tpl->assign('url', $entry[0]['url']); | ||
22 | $tpl->assign('title', $entry[0]['title']); | ||
23 | $tpl->assign('content', $entry[0]['content']); | ||
24 | $tpl->assign('is_fav', $entry[0]['is_fav']); | ||
25 | $tpl->assign('is_read', $entry[0]['is_read']); | ||
26 | $tpl->assign('load_all_js', 0); | ||
27 | $tpl->draw('view'); | ||
28 | } | ||
29 | else { | ||
30 | logm('error in view call : entry is NULL'); | ||
31 | } | ||
32 | } | ||
33 | else { | ||
34 | logm('error in view call : id is empty'); | ||
35 | } \ No newline at end of file | ||