Merge pull request #460 from ArthurHoaro/440-editlink-404
Fixes #440 - 404 error after editing a link
This commit is contained in:
commit
6cbff7e80f
1 changed files with 34 additions and 13 deletions
47
index.php
47
index.php
|
@ -1552,21 +1552,40 @@ function renderPage()
|
||||||
// -------- User clicked the "Save" button when editing a link: Save link to database.
|
// -------- User clicked the "Save" button when editing a link: Save link to database.
|
||||||
if (isset($_POST['save_edit']))
|
if (isset($_POST['save_edit']))
|
||||||
{
|
{
|
||||||
if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away!
|
// Go away!
|
||||||
$tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces.
|
if (! tokenOk($_POST['token'])) {
|
||||||
$tags = implode(' ', array_unique(explode(' ', $tags))); // Remove duplicates.
|
die('Wrong token.');
|
||||||
$linkdate=$_POST['lf_linkdate'];
|
}
|
||||||
|
// Remove multiple spaces.
|
||||||
|
$tags = trim(preg_replace('/\s\s+/', ' ', $_POST['lf_tags']));
|
||||||
|
// Remove duplicates.
|
||||||
|
$tags = implode(' ', array_unique(explode(' ', $tags)));
|
||||||
|
$linkdate = $_POST['lf_linkdate'];
|
||||||
$url = trim($_POST['lf_url']);
|
$url = trim($_POST['lf_url']);
|
||||||
if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?') && !startsWith($url,'javascript:'))
|
if (! startsWith($url, 'http:') && ! startsWith($url, 'https:')
|
||||||
$url = 'http://'.$url;
|
&& ! startsWith($url, 'ftp:') && ! startsWith($url, 'magnet:')
|
||||||
$link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0),
|
&& ! startsWith($url, '?') && ! startsWith($url, 'javascript:')
|
||||||
'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags));
|
) {
|
||||||
if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title.
|
$url = 'http://' . $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = array(
|
||||||
|
'title' => trim($_POST['lf_title']),
|
||||||
|
'url' => $url,
|
||||||
|
'description' => trim($_POST['lf_description']),
|
||||||
|
'private' => (isset($_POST['lf_private']) ? 1 : 0),
|
||||||
|
'linkdate' => $linkdate,
|
||||||
|
'tags' => str_replace(',', ' ', $tags)
|
||||||
|
);
|
||||||
|
// If title is empty, use the URL as title.
|
||||||
|
if ($link['title'] == '') {
|
||||||
|
$link['title'] = $link['url'];
|
||||||
|
}
|
||||||
|
|
||||||
$pluginManager->executeHooks('save_link', $link);
|
$pluginManager->executeHooks('save_link', $link);
|
||||||
|
|
||||||
$LINKSDB[$linkdate] = $link;
|
$LINKSDB[$linkdate] = $link;
|
||||||
$LINKSDB->savedb($GLOBALS['config']['PAGECACHE']); // Save to disk.
|
$LINKSDB->savedb($GLOBALS['config']['PAGECACHE']);
|
||||||
pubsubhub();
|
pubsubhub();
|
||||||
|
|
||||||
// If we are called from the bookmarklet, we must close the popup:
|
// If we are called from the bookmarklet, we must close the popup:
|
||||||
|
@ -1575,10 +1594,12 @@ function renderPage()
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$returnurl = !empty($_POST['returnurl']) ? escape($_POST['returnurl']): '?';
|
$returnurl = !empty($_POST['returnurl']) ? $_POST['returnurl'] : '?';
|
||||||
$location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link'));
|
$location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link'));
|
||||||
$location .= '#'.smallHash($_POST['lf_linkdate']); // Scroll to the link which has been edited.
|
// Scroll to the link which has been edited.
|
||||||
header('Location: '. $location); // After saving the link, redirect to the page the user was on.
|
$location .= '#' . smallHash($_POST['lf_linkdate']);
|
||||||
|
// After saving the link, redirect to the page the user was on.
|
||||||
|
header('Location: '. $location);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue