aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-11-05 14:13:18 +0100
committerArthurHoaro <arthur@hoa.ro>2016-12-16 12:42:13 +0100
commitf4ebd5fed20b29c4fb580983b4be7bd0a52151b9 (patch)
treec102ff1526c467b1869ed72bbd68c6f39997f529
parente3ffc8fdee30be41046b985fe6e7034fb580b0c8 (diff)
downloadShaarli-f4ebd5fed20b29c4fb580983b4be7bd0a52151b9.tar.gz
Shaarli-f4ebd5fed20b29c4fb580983b4be7bd0a52151b9.tar.zst
Shaarli-f4ebd5fed20b29c4fb580983b4be7bd0a52151b9.zip
Bugfixes on link deletion, and use a GET form
Use a GET form to delete links: harmonize with edit_link and preparation for #585 Bug fixes: * LinkDB element can't be passed as reference, fix error: PHP Notice: Indirect modification of overloaded element of LinkDB has no effect * Resource cache folder setting wasn't set correctly
-rw-r--r--application/Router.php6
-rw-r--r--index.php16
-rw-r--r--tpl/linklist.html2
3 files changed, 15 insertions, 9 deletions
diff --git a/application/Router.php b/application/Router.php
index caed4a28..c9a51912 100644
--- a/application/Router.php
+++ b/application/Router.php
@@ -31,6 +31,8 @@ class Router
31 31
32 public static $PAGE_EDITLINK = 'edit_link'; 32 public static $PAGE_EDITLINK = 'edit_link';
33 33
34 public static $PAGE_DELETELINK = 'delete_link';
35
34 public static $PAGE_EXPORT = 'export'; 36 public static $PAGE_EXPORT = 'export';
35 37
36 public static $PAGE_IMPORT = 'import'; 38 public static $PAGE_IMPORT = 'import';
@@ -120,6 +122,10 @@ class Router
120 return self::$PAGE_EDITLINK; 122 return self::$PAGE_EDITLINK;
121 } 123 }
122 124
125 if (isset($get['delete_link'])) {
126 return self::$PAGE_DELETELINK;
127 }
128
123 if (startsWith($query, 'do='. self::$PAGE_EXPORT)) { 129 if (startsWith($query, 'do='. self::$PAGE_EXPORT)) {
124 return self::$PAGE_EXPORT; 130 return self::$PAGE_EXPORT;
125 } 131 }
diff --git a/index.php b/index.php
index a0a3a8c7..34f0e381 100644
--- a/index.php
+++ b/index.php
@@ -1325,21 +1325,21 @@ function renderPage($conf, $pluginManager)
1325 } 1325 }
1326 1326
1327 // -------- User clicked the "Delete" button when editing a link: Delete link from database. 1327 // -------- User clicked the "Delete" button when editing a link: Delete link from database.
1328 if (isset($_POST['delete_link'])) 1328 if ($targetPage == Router::$PAGE_DELETELINK)
1329 { 1329 {
1330 if (!tokenOk($_POST['token'])) die('Wrong token.');
1331
1332 // We do not need to ask for confirmation: 1330 // We do not need to ask for confirmation:
1333 // - confirmation is handled by JavaScript 1331 // - confirmation is handled by JavaScript
1334 // - we are protected from XSRF by the token. 1332 // - we are protected from XSRF by the token.
1335 1333
1336 // FIXME! We keep `lf_linkdate` for consistency before a proper API. To be removed. 1334 if (! tokenOk($_GET['token'])) {
1337 $id = isset($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : intval(escape($_POST['lf_linkdate'])); 1335 die('Wrong token.');
1338 1336 }
1339 $pluginManager->executeHooks('delete_link', $LINKSDB[$id]);
1340 1337
1338 $id = intval(escape($_GET['lf_linkdate']));
1339 $link = $LINKSDB[$id];
1340 $pluginManager->executeHooks('delete_link', $link);
1341 unset($LINKSDB[$id]); 1341 unset($LINKSDB[$id]);
1342 $LINKSDB->save('resource.page_cache'); // save to disk 1342 $LINKSDB->save($conf->get('resource.page_cache')); // save to disk
1343 1343
1344 // If we are called from the bookmarklet, we must close the popup: 1344 // If we are called from the bookmarklet, we must close the popup:
1345 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; } 1345 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; }
diff --git a/tpl/linklist.html b/tpl/linklist.html
index 0f1a5e8c..d4232342 100644
--- a/tpl/linklist.html
+++ b/tpl/linklist.html
@@ -84,7 +84,7 @@
84 <input type="hidden" name="edit_link" value="{$value.id}"> 84 <input type="hidden" name="edit_link" value="{$value.id}">
85 <input type="image" alt="Edit" src="images/edit_icon.png#" title="Edit" class="button_edit"> 85 <input type="image" alt="Edit" src="images/edit_icon.png#" title="Edit" class="button_edit">
86 </form><br> 86 </form><br>
87 <form method="POST" class="buttoneditform"> 87 <form method="GET" class="buttoneditform">
88 <input type="hidden" name="lf_linkdate" value="{$value.id}"> 88 <input type="hidden" name="lf_linkdate" value="{$value.id}">
89 <input type="hidden" name="token" value="{$token}"> 89 <input type="hidden" name="token" value="{$token}">
90 <input type="hidden" name="delete_link"> 90 <input type="hidden" name="delete_link">