From 5eca0c74770bf7da56b524c84d1ccf9aa148015e Mon Sep 17 00:00:00 2001 From: Ben Schell Date: Mon, 30 Apr 2012 16:11:33 -0400 Subject: [PATCH] Adding "Mark Gone" capability to effectively remove a slug. --- -/index.php | 19 ++++++++++++++++++- -/pages/stats.php | 4 ++++ -/stats.php | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/-/index.php b/-/index.php index 37e1e5a..72929b4 100644 --- a/-/index.php +++ b/-/index.php @@ -550,7 +550,24 @@ function bc_log($message){ } elseif(isset($_GET['mark_gone']) && isset($_GET['slug']) && strlen(trim($_GET['slug']))) { // Mark a redirection as GONE - // TODO + $prefix = DB_PREFIX; + $slug = $_GET['slug']; + + // Check if slug is in use + $stmt = $db->prepare("SELECT url, checksum, custom_url, redir_type FROM {$prefix}urls WHERE BINARY custom_url = BINARY :slug AND custom_url = :slug"); + $stmt->execute(array('slug'=>$slug)); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + if($row){ // slug exists + $result = bcurls_update_slug($row['url'], $row['checksum'], $row['custom_url'], 'gone'); + if($result !== true) { + $error = $insert_result; + include('pages/error.php'); + exit; + } + } + // Redirect to the stats page + header('Location:?stats=1'); + exit(); } else { diff --git a/-/pages/stats.php b/-/pages/stats.php index cdf38df..360c806 100644 --- a/-/pages/stats.php +++ b/-/pages/stats.php @@ -7,6 +7,8 @@ URL Lessn'd Hits + Active? + Mark Gone + + Mark Gone diff --git a/-/stats.php b/-/stats.php index af164e2..0b637b1 100644 --- a/-/stats.php +++ b/-/stats.php @@ -10,7 +10,7 @@ function record_stats($db, $url_id) { } function stats_top_urls($db, $count=10) { - $stmt = $db->query('SELECT u.id,u.url,u.custom_url,COUNT(s.url_id) as hits FROM '.DB_PREFIX.'urls u LEFT JOIN '.DB_PREFIX.'url_stats s ON u.id = s.url_id GROUP BY u.id,u.url ORDER BY hits desc LIMIT '.$count); + $stmt = $db->query('SELECT u.id,u.url,u.custom_url,u.redir_type,COUNT(s.url_id) as hits FROM '.DB_PREFIX.'urls u LEFT JOIN '.DB_PREFIX.'url_stats s ON u.id = s.url_id GROUP BY u.id,u.url ORDER BY hits desc LIMIT '.$count); return $stmt->fetchAll(PDO::FETCH_ASSOC); }