From ef591e7ee21435da9314c5f7f6ea983c6f423898 Mon Sep 17 00:00:00 2001 From: Guillaume Virlet Date: Wed, 2 Sep 2015 13:55:39 +0200 Subject: Url: introduce global helper functions for cleanup and scheme detection Relates to #314 & #326 Additions: - add global `cleanup_url()` and `get_url_scheme()` functions Modifications: - replace `Url` usage in `index.php` by calls to global functions - fix `Url` tests not being run: PHPUnit expects a single test class per file - move classes to separate files --- index.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index e39cff38..61d92f04 100755 --- a/index.php +++ b/index.php @@ -1454,12 +1454,11 @@ function renderPage() // -------- User want to post a new link: Display link edit form. if (isset($_GET['post'])) { - $url = new Url($_GET['post']); - $url->cleanup(); + $url = cleanup_url($_GET['post']); $link_is_new = false; // Check if URL is not already in database (in this case, we will edit the existing link) - $link = $LINKSDB->getLinkFromUrl((string)$url); + $link = $LINKSDB->getLinkFromUrl($url); if (!$link) { $link_is_new = true; @@ -1471,7 +1470,7 @@ function renderPage() $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // If this is an HTTP(S) link, we try go get the page to extract the title (otherwise we will to straight to the edit form.) - if (empty($title) && strpos($url->getScheme(), 'http') !== false) { + if (empty($title) && strpos(get_url_scheme($url), 'http') !== false) { // Short timeout to keep the application responsive list($headers, $data) = get_http_url($url, 4); // FIXME: Decode charset according to specified in either 1) HTTP response headers or 2) in html @@ -1505,7 +1504,7 @@ function renderPage() $link = array( 'linkdate' => $linkdate, 'title' => $title, - 'url' => (string)$url, + 'url' => $url, 'description' => $description, 'tags' => $tags, 'private' => $private -- cgit v1.2.3