Code cleanup: index.php - save_edit

This commit is contained in:
ArthurHoaro 2016-02-04 19:58:47 +01:00
parent 268a2e5265
commit 5a23950c95

View file

@ -1526,21 +1526,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:
@ -1551,8 +1570,10 @@ function renderPage()
$returnurl = !empty($_POST['returnurl']) ? escape($_POST['returnurl']): '?'; $returnurl = !empty($_POST['returnurl']) ? escape($_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;
} }