]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
tout est recentré sur index.php 0.1
authornicosomb <nicolas@loeuillet.org>
Fri, 19 Apr 2013 09:41:12 +0000 (11:41 +0200)
committernicosomb <nicolas@loeuillet.org>
Fri, 19 Apr 2013 09:41:12 +0000 (11:41 +0200)
inc/Session.class.php
inc/config.php
inc/functions.php
index.php
js/poche.js
process.php [deleted file]
tpl/entries.html
tpl/home.html
tpl/login.html
tpl/view.html
view.php [deleted file]

index 06fa6a8ecfa82a593e56345dda19325a69586b63..ee12b3d155e1ae15f210dda5d8cf6e5e6d27e29d 100644 (file)
@@ -93,7 +93,7 @@ class Session
     // Force 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.
index 403217ce6d95d1defb675909a534cbaf28e29ea3..063952a51e2c046d007d3fc290b20743f2b47c5b 100644 (file)
@@ -33,59 +33,4 @@ raintpl::$cache_dir = './cache/';
 raintpl::$base_url  = get_poche_url();
 raintpl::configure('path_replace', false);
 raintpl::configure('debug', false);
-$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);
-}
+$tpl = new raintpl();
\ No newline at end of file
index 13acd36f30840d88675b0e7144c9df27a5cf0392..ef1fc0e28a934812df50d1468d2874d2395aa60e 100644 (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)
  */
-
 function action_to_do($action, $url, $id = 0)
 {
     global $db;
index 995426b456b8b6cdfe33a66c1711a3ce3d452b8f..9a81a74104f2f739fa5e059c4915bacdf923a687 100644 (file)
--- a/index.php
+++ b/index.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('entries', $entries);
-$tpl->assign('load_all_js', 1);
 
-$tpl->draw('head');
 if (Session::isLogged()) {
-    $tpl->draw('home');
-    $tpl->draw('entries');
-    $tpl->draw('js');
+    action_to_do($action, $url, $id);
+    display_view($view, $id, $full_head);
 }
 else {
     $tpl->draw('login');
-}
-$tpl->draw('footer');
\ No newline at end of file
+}
\ No newline at end of file
index 98fc48ea3f5fba7af2afaa9099df76b394d40a89..6bc3c188aa6a0857daa841ad7bd0f1483d435bc7 100644 (file)
@@ -1,16 +1,16 @@
-function toggle_favorite(element, id, token) {
+function toggle_favorite(element, id) {
     $(element).toggleClass('fav-off');
     $.ajax ({
         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');
     $.ajax ({
         url: "index.php?action=toggle_archive",
-        data:{id:id, token:token}
+        data:{id:id}
     });
     var obj = $('#entry-'+id);
 
@@ -22,6 +22,9 @@ function toggle_archive(element, id, token, view_article) {
     }
 }
 
-function sort_links(view, sort, token) {
-    $('#content').load('process.php', { view: view, sort: sort, token: token } );
+function sort_links(view, sort) {
+    //$('#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);
+    });
 }
\ No newline at end of file
diff --git a/process.php b/process.php
deleted file mode 100644 (file)
index 1468688..0000000
+++ /dev/null
@@ -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');
\ No newline at end of file
index c74bc34672054ac69194326a8173cc01a40aae1a..648e1ce9d85098a8dadfbf9754fd61807745de63 100644 (file)
@@ -2,13 +2,13 @@
                     <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>
+                                <a href="index.php?&view=view&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}, '<?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}, '<?php echo Session::getToken(); ?>')"><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><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})"><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="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>
                             </div>
                         </span>
index 216f39b9bec09e12f12d886fb90331ed205adb17..6fb9444cd3bb1e7e00020888f67d011904ae7d8a 100644 (file)
@@ -6,7 +6,7 @@
                 <li><a href="?logout" title="Logout">logout</a></li>
             </ul>
             <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}', '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}', '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');" title="by title asc" /> by title <img src="img/down.png" onclick="sort_links('{$view}', 'td');" title="by title desc" /></li>
             </ul>
             <div id="content">
\ No newline at end of file
index bf0f4fa67f36c57c2cd66263895b68511b8da1b1..d3139ab36ec779e7e930da23bfcc6047256200e0 100644 (file)
@@ -1,3 +1,4 @@
+{include="head"}
             <form method="post" action="?login" name="loginform">
                 <fieldset>
                     <h2>login to your poche</h2>
@@ -18,4 +19,5 @@
                 </fieldset>
                 <input type="hidden" name="returnurl" value="<?php echo htmlspecialchars($referer);?>">
                 <input type="hidden" name="token" value="<?php echo Session::getToken(); ?>">
-            </form>
\ No newline at end of file
+            </form>
+{include="footer"}
\ No newline at end of file
index 1191bd8234e8301796e8dc641a213825521ce90d..4b8ce60fbba104c25362dc0ccd758dc8a346f607 100644 (file)
                </div>
             <div class="tools">
                 <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 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><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><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})"><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="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>
             </div>
             <header class="mbm">
diff --git a/view.php b/view.php
deleted file mode 100644 (file)
index 29a5b32..0000000
--- a/view.php
+++ /dev/null
@@ -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');
-}
\ No newline at end of file