$url = rawurldecode( $_GET['up'] . $_GET['us'] . $_GET['ur'] );
}
$keyword = ( isset( $_GET['k'] ) ? ( $_GET['k'] ) : '' );
$title = ( isset( $_GET['t'] ) ? ( $_GET['t'] ) : '' );
$return = yourls_add_new_link( $url, $keyword, $title );
// If fails because keyword already exist, retry with no keyword
if ( isset( $return['status'] ) && $return['status'] == 'fail' && isset( $return['code'] ) && $return['code'] == 'error:keyword' ) {
$msg = $return['message'];
$return = yourls_add_new_link( $url, '', $ydb );
$return['message'] .= ' ('.$msg.')';
}
// Stop here if bookmarklet with a JSON callback function
if( isset( $_GET['jsonp'] ) && $_GET['jsonp'] == 'yourls' ) {
$short = $return['shorturl'] ? $return['shorturl'] : '';
$message = $return['message'];
yourls_content_type_header( 'application/javascript' );
echo yourls_apply_filter( 'bookmarklet_jsonp', "yourls_callback({'short_url':'$short','message':'$message'});" );
die();
}
// Now use the URL that has been sanitized and returned by yourls_add_new_link()
$url = $return['url']['url'];
$where = sprintf( " AND `url` LIKE '%s' ", yourls_escape( $url ) );
$page = $total_pages = $perpage = 1;
$offset = 0;
$text = ( isset( $_GET['s'] ) ? stripslashes( $_GET['s'] ) : '' );
// Sharing with social bookmarklets
if( !empty($_GET['share']) ) {
yourls_do_action( 'pre_share_redirect' );
switch ( $_GET['share'] ) {
case 'twitter':
// share with Twitter
$destination = sprintf( "https://twitter.com/intent/tweet?url=%s&text=%s", urlencode( $return['shorturl'] ), urlencode( $title ) );
yourls_redirect( $destination, 303 );
// Deal with the case when redirection failed:
$return['status'] = 'error';
$return['errorCode'] = 400;
$return['message'] = yourls_s( 'Short URL created, but could not redirect to %s !', 'Twitter' );
break;
case 'facebook':
// share with Facebook
$destination = sprintf( "https://www.facebook.com/sharer/sharer.php?u=%s&t=%s", urlencode( $return['shorturl'] ), urlencode( $title ) );
yourls_redirect( $destination, 303 );
// Deal with the case when redirection failed:
$return['status'] = 'error';
$return['errorCode'] = 400;
$return['message'] = yourls_s( 'Short URL created, but could not redirect to %s !', 'Facebook' );
break;
case 'tumblr':
// share with Tumblr
$destination = sprintf( "http://www.tumblr.com/share?v=3&u=%s&t=%s&s=%s", urlencode( $return['shorturl'] ), urlencode( $title ), urlencode( $text ) );
yourls_redirect( $destination, 303 );
// Deal with the case when redirection failed:
$return['status'] = 'error';
$return['errorCode'] = 400;
$return['message'] = yourls_s( 'Short URL created, but could not redirect to %s !', 'Tumblr' );
break;
default:
// Is there a custom registered social bookmark?
yourls_do_action( 'share_redirect_' . $_GET['share'], $return );
// Still here? That was an unknown 'share' method, then.
$return['status'] = 'error';
$return['errorCode'] = 400;
$return['message'] = yourls__( 'Unknown "Share" bookmarklet' );
break;
}
}
// This is not a bookmarklet
} else {
$is_bookmark = false;
// Checking $page, $offset, $perpage
if( empty($page) || $page == 0 ) {
$page = 1;
}
if( empty($offset) ) {
$offset = 0;
}
if( empty($perpage) || $perpage == 0) {
$perpage = 50;
}
// Determine $offset
$offset = ( $page-1 ) * $perpage;
// Determine Max Number Of Items To Display On Page
if( ( $offset + $perpage ) > $total_items ) {
$max_on_page = $total_items;
} else {
$max_on_page = ( $offset + $perpage );
}
// Determine Number Of Items To Display On Page
if ( ( $offset + 1 ) > $total_items ) {
$display_on_page = $total_items;
} else {
$display_on_page = ( $offset + 1 );
}
// Determing Total Amount Of Pages
$total_pages = ceil( $total_items / $perpage );
}
// Begin output of the page
$context = ( $is_bookmark ? 'bookmark' : 'index' );
yourls_html_head( $context );
yourls_html_logo();
yourls_html_menu() ;
yourls_do_action( 'admin_page_before_content' );
if ( !$is_bookmark ) { ?>
%1$s to %2$s of %3$s URLs' ), $display_on_page, $max_on_page, $total_items );
if( $total_items_clicks !== false )
echo ", " . sprintf( yourls_n( 'counting 1 click', 'counting %s clicks', $total_items_clicks ), yourls_number_format_i18n( $total_items_clicks ) );
?>.
%1$s links, %2$s clicks, and counting!' ), yourls_number_format_i18n( $total_urls ), yourls_number_format_i18n( $total_clicks ) ); ?>
$(document).ready(function(){
feedback( "' . $return['message'] . '", "'. $return['status'] .'");
init_clipboard();
});';
}
yourls_do_action( 'admin_page_before_table' );
yourls_table_head();
if ( !$is_bookmark ) {
$params = array(
'search' => $search,
'search_text' => $search_text,
'search_in' => $search_in,
'sort_by' => $sort_by,
'sort_order' => $sort_order,
'page' => $page,
'perpage' => $perpage,
'click_filter' => $click_filter,
'click_limit' => $click_limit,
'total_pages' => $total_pages,
'date_filter' => $date_filter,
'date_first' => $date_first,
'date_second' => $date_second,
);
yourls_html_tfooter( $params );
}
yourls_table_tbody_start();
// Main Query
$where = yourls_apply_filter( 'admin_list_where', $where );
$url_results = $ydb->get_results( "SELECT * FROM `$table_url` WHERE 1=1 $where ORDER BY `$sort_by` $sort_order LIMIT $offset, $perpage;" );
$found_rows = false;
if( $url_results ) {
$found_rows = true;
foreach( $url_results as $url_result ) {
$keyword = yourls_sanitize_string( $url_result->keyword );
$timestamp = strtotime( $url_result->timestamp );
$url = stripslashes( $url_result->url );
$ip = $url_result->ip;
$title = $url_result->title ? $url_result->title : '';
$clicks = $url_result->clicks;
echo yourls_table_add_row( $keyword, $url, $title, $ip, $clicks, $timestamp );
}
}
$display = $found_rows ? 'display:none' : '';
echo '' . yourls__('No URL') . ' |
';
yourls_table_tbody_end();
yourls_table_end();
yourls_do_action( 'admin_page_after_table' );
if ( $is_bookmark )
yourls_share_box( $url, $return['shorturl'], $title, $text );
?>