From cd8a3b2bf6bb5fd0280c196bb5e1ddf30c73e8ea Mon Sep 17 00:00:00 2001 From: ozhozh Date: Sun, 4 Oct 2009 12:40:37 +0000 Subject: [PATCH] - Fixed JS error when editing a link - Add ?version= when inserting a JS or CSS in the head git-svn-id: http://yourls.googlecode.com/svn/trunk@217 12232710-3e20-11de-b438-597f59cd7555 --- includes/functions.php | 34 ++++++++++++++++++---------------- js/insert.js | 4 +++- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index ae36b71..ee4f11d 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -166,7 +166,7 @@ function yourls_table_add_row( $keyword, $url, $ip, $clicks, $timestamp ) { $statlink = $shorturl.'+'; return <<$keyword$display_url$date$ip$clicks      +$keyword$display_url$date$ip$clicks      ROW; } @@ -294,6 +294,8 @@ function yourls_edit_link($url, $keyword, $newkeyword='') { $newkeyword = yourls_sanitize_string( $newkeyword ); $strip_url = stripslashes($url); $old_url = $ydb->get_var("SELECT `url` FROM `$table` WHERE `keyword` = '$keyword';"); + $old_id = $id = yourls_string2int( $keyword ); + $new_id = ( $newkeyword == '' ? $old_id : yourls_string2int( $newkeyword ) ); // Check if new URL is not here already if ($old_url != $url) { @@ -310,12 +312,12 @@ function yourls_edit_link($url, $keyword, $newkeyword='') { } // All clear, update - if ( !$new_url_already_there && $keyword_is_ok ) { - $timestamp4screen = date( 'Y M d H:i', time()+( YOURLS_HOURS_OFFSET * 3600) ); - $timestamp4db = date('Y-m-d H:i:s', time()+( YOURLS_HOURS_OFFSET * 3600) ); - $update_url = $ydb->query("UPDATE `$table` SET `url` = '$url', `timestamp` = '$timestamp4db', `keyword` = '$newkeyword' WHERE `keyword` = '$keyword';"); + if ( ( !$new_url_already_there || yourls_allow_duplicate_longurls() ) && $keyword_is_ok ) { + //$timestamp4screen = date( 'Y M d H:i', time()+( YOURLS_HOURS_OFFSET * 3600) ); + //$timestamp4db = date('Y-m-d H:i:s', time()+( YOURLS_HOURS_OFFSET * 3600) ); + $update_url = $ydb->query("UPDATE `$table` SET `url` = '$url', `keyword` = '$newkeyword' WHERE `keyword` = '$keyword';"); if( $update_url ) { - $return['url'] = array( 'keyword' => $newkeyword, 'shorturl' => YOURLS_SITE.'/'.$newkeyword, 'url' => $strip_url, 'date' => $timestamp4screen); + $return['url'] = array( 'keyword' => $newkeyword, 'shorturl' => YOURLS_SITE.'/'.$newkeyword, 'url' => $strip_url, 'display_url' => yourls_trim_long_string( $strip_url ), 'new_id' => $new_id ); $return['status'] = 'success'; $return['message'] = 'Link updated in database'; } else { @@ -620,26 +622,26 @@ function yourls_html_head( $context = 'index' ) { YOURLS » Your Own URL Shortener | <?php echo YOURLS_SITE; ?> - + - - + + - - + + - - + + - + - - + + diff --git a/js/insert.js b/js/insert.js index f2c13aa..ac585a0 100644 --- a/js/insert.js +++ b/js/insert.js @@ -108,12 +108,14 @@ function edit_save(id) { {mode:'edit_save', url: newurl, keyword: keyword, newkeyword: newkeyword }, function(data){ if(data.status == 'success') { - $("#url-" + id).html('' + data.url.url + ''); + $("#url-" + id).html('' + data.url.display_url + ''); $("#keyword-" + id).html('' + data.url.keyword + ''); $("#timestamp-" + id).html(data.url.date); $("#edit-" + id).fadeOut(200, function(){ $('#tblUrl tbody').trigger("update"); }); + $('#keyword_'+id).val( newkeyword ); + $('#statlink-'+id).attr( 'href', data.url.shorturl+'+' ); } feedback(data.message, data.status); end_disable("#edit-close-" + id); -- 2.45.0