From ed6bc91397d8350c0075c837dbc0769eae8bbfd4 Mon Sep 17 00:00:00 2001 From: zPlus <-> Date: Thu, 21 Apr 2016 14:47:57 +0200 Subject: [PATCH] New submission: add HTTP as default URL Scheme when missing --- submit.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/submit.php b/submit.php index 45fba671..35d2a7db 100644 --- a/submit.php +++ b/submit.php @@ -33,8 +33,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') exit (); } - // Title is ok, add the new post - $post_hash_id = $db->new_post ($title, $_POST['link'], $_POST['text'], Session::get_userid()); + // Normalize Link + $link = trim ($_POST['link']); + + if (strlen ($link) > 0) + { + $link_components = parse_url ($link); + + if (!isset ($link_components['scheme'])) + $link = 'http://' . $link; + } + + // Add the new post + $post_hash_id = $db->new_post ($title, $link, $_POST['text'], Session::get_userid()); // Redirect to the new post page header ('Location: ./post/' . $post_hash_id);