From 260516aea2dc2bec4cfa0fd1296d82e556c1aece Mon Sep 17 00:00:00 2001 From: ozhozh Date: Fri, 25 Jun 2010 16:13:25 +0000 Subject: [PATCH] Store URL titles in DB when displaying stats page git-svn-id: http://yourls.googlecode.com/svn/trunk@417 12232710-3e20-11de-b438-597f59cd7555 --- includes/functions.php | 16 ++++++++++++++++ yourls-infos.php | 11 +++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index db2a63b..8d8a133 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -484,6 +484,19 @@ function yourls_edit_link( $url, $keyword, $newkeyword='', $title='' ) { return yourls_apply_filter( 'edit_link', $return, $url, $keyword, $newkeyword, $new_url_already_there, $keyword_is_ok ); } +// Update a title link (no checks for duplicates etc..) +function yourls_edit_link_title( $keyword, $title ) { + global $ydb; + + $keyword = yourls_escape( yourls_sanitize_keyword( $keyword ) ); + $title = yourls_escape( yourls_sanitize_title( $title ) ); + + $table = YOURLS_DB_TABLE_URL; + $update = $ydb->query("UPDATE `$table` SET `title` = '$title' WHERE `keyword` = '$keyword';"); + + return $update; +} + // Check if keyword id is free (ie not already taken, and not reserved). Return bool. function yourls_keyword_is_free( $keyword ) { @@ -1473,6 +1486,9 @@ function yourls_get_remote_title( $url ) { if( $title == false && strpos( $content, 'Error' ) === 0 ) { $title = $content; } + + if( $title == false ) + $title = $url; $title = yourls_sanitize_title( $title ); diff --git a/yourls-infos.php b/yourls-infos.php index 13305d0..f99c8e0 100644 --- a/yourls-infos.php +++ b/yourls-infos.php @@ -21,6 +21,13 @@ $longurl = yourls_get_keyword_longurl( $keyword ); $clicks = yourls_get_keyword_clicks( $keyword ); $timestamp = yourls_get_keyword_timestamp( $keyword ); +$title = yourls_get_keyword_title( $keyword ); + +// Update title if it hasn't been stored yet +if( $title == '' ) { + $title = yourls_get_remote_title( $longurl ); + yourls_edit_link_title( $keyword, $title ); +} if ( $longurl === false ) { yourls_do_action( 'infos_keyword_not_found' ); @@ -167,7 +174,7 @@ yourls_html_menu(); ?> -

Information

+

Short URL: 1 ) echo ' '; } ?>

-

Long URL:

+

Long URL:

-- 2.45.0