]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #682 from ArthurHoaro/delete-button
authorArthur <arthur@hoa.ro>
Wed, 4 Jan 2017 15:35:29 +0000 (16:35 +0100)
committerGitHub <noreply@github.com>
Wed, 4 Jan 2017 15:35:29 +0000 (16:35 +0100)
Bugfixes on link deletion, and use a GET form

application/Router.php
index.php
tpl/linklist.html

index caed4a281619f56aefd0482575dd2427510208de..c9a519120eecf3274c1b66a7df5f4e2deacbec95 100644 (file)
@@ -31,6 +31,8 @@ class Router
 
     public static $PAGE_EDITLINK = 'edit_link';
 
+    public static $PAGE_DELETELINK = 'delete_link';
+
     public static $PAGE_EXPORT = 'export';
 
     public static $PAGE_IMPORT = 'import';
@@ -120,6 +122,10 @@ class Router
             return self::$PAGE_EDITLINK;
         }
 
+        if (isset($get['delete_link'])) {
+            return self::$PAGE_DELETELINK;
+        }
+
         if (startsWith($query, 'do='. self::$PAGE_EXPORT)) {
             return self::$PAGE_EXPORT;
         }
index bb1debd3f515bcd5bf2a3b892b3b60890812c092..2ed14d4f2f3ac67ed6bd5e041fc434b27a7aa050 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1316,21 +1316,21 @@ function renderPage($conf, $pluginManager, $LINKSDB)
     }
 
     // -------- User clicked the "Delete" button when editing a link: Delete link from database.
-    if (isset($_POST['delete_link']))
+    if ($targetPage == Router::$PAGE_DELETELINK)
     {
-        if (!tokenOk($_POST['token'])) die('Wrong token.');
-
         // We do not need to ask for confirmation:
         // - confirmation is handled by JavaScript
         // - we are protected from XSRF by the token.
 
-        // FIXME! We keep `lf_linkdate` for consistency before a proper API. To be removed.
-        $id = isset($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : intval(escape($_POST['lf_linkdate']));
-
-        $pluginManager->executeHooks('delete_link', $LINKSDB[$id]);
+        if (! tokenOk($_GET['token'])) {
+            die('Wrong token.');
+        }
 
+        $id = intval(escape($_GET['lf_linkdate']));
+        $link = $LINKSDB[$id];
+        $pluginManager->executeHooks('delete_link', $link);
         unset($LINKSDB[$id]);
-        $LINKSDB->save('resource.page_cache'); // save to disk
+        $LINKSDB->save($conf->get('resource.page_cache')); // save to disk
 
         // If we are called from the bookmarklet, we must close the popup:
         if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; }
index 0f1a5e8ca9911ed164ee147ef3227bc9c0adf443..d42323423bc3411bc75de98ecda8bf0ead6cb6ac 100644 (file)
@@ -84,7 +84,7 @@
                             <input type="hidden" name="edit_link" value="{$value.id}">
                             <input type="image" alt="Edit" src="images/edit_icon.png#" title="Edit" class="button_edit">
                         </form><br>
-                        <form method="POST" class="buttoneditform">
+                        <form method="GET" class="buttoneditform">
                             <input type="hidden" name="lf_linkdate" value="{$value.id}">
                             <input type="hidden" name="token" value="{$token}">
                             <input type="hidden" name="delete_link">