From d2d7fa701bccaf12a3e85467d68b3886c6050f92 Mon Sep 17 00:00:00 2001 From: Clayton Daley Date: Sat, 9 Nov 2013 18:19:54 -0500 Subject: [PATCH] Added sort (order by) options to new yours_get_keywords() function. --- includes/functions.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 4d6329f..8df7d28 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1225,12 +1225,19 @@ function yourls_get_duplicate_keywords( $longurl ) { return yourls_get_keywords ( $longurl ); } -function yourls_get_keywords( $longurl ) { +function yourls_get_keywords( $longurl, $sort = 'none', $order = 'ASC' ) { global $ydb; $longurl = yourls_escape( yourls_sanitize_url($longurl) ); $table = YOURLS_DB_TABLE_URL; - $return = $ydb->get_col( "SELECT `keyword` FROM `$table` WHERE `url` = '$longurl'" ); + $query = "SELECT `keyword` FROM `$table` WHERE `url` = '$longurl'"; + // Ensure valid keyword, update as necessary + if ( in_array( $sort, ('keyword','title','timestamp','clicks') ) ) { + $query .= " ORDER BY '".$sort."'"; + // ASC is default + if ( in_array( $order, ('ASC','DESC') ) ) $query .= " ".$order; + } + $return = $ydb->get_col( $query ); return yourls_apply_filter( 'get_duplicate_keywords', $return, $longurl ); } -- 2.45.0