diff --git a/submit.php b/submit.php index 45fba67..35d2a7d 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);